您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

答案是:

@RequestMapping(value = "/game/play", method = RequestMethod.POST)
@ResponseBody
public 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;
}
其他 2022/1/1 18:17:27 有495人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶