在JPA中将实体列表保存在具有ManyToOne关系的数据库中

在JPA中将实体列表保存在具有ManyToOne关系的数据库中,第1张

在JPA中将实体列表保存在具有ManyToOne关系的数据库中

答案是:

@RequestMapping(value = "/game/play", method = RequestMethod.POST)@ResponseBodypublic User indexRequestPlay(@RequestParam String username, @RequestParam String password) {    User user = userRepository.findByUsernameAndPassword(username, password);    Random random = new Random();    int userScore = random.nextInt(5) + 1;    int npcScore = random.nextInt(5) + 1;    /////////////////////////////////////////////////////////////////////////////////    // aici adaug un camp in user.    user.getStartSessions().add(new Date());    /////////////////////////////////////////////////////////////////////////////////    Game game = new Game(userScore, npcScore, new Date());    game.setUser(user);    user.getGames().add(game);    userRepository.save(user);    return user;}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5084974.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-16
下一篇2022-11-16

发表评论

登录后才能评论

评论列表(0条)

    保存