首页 > 编程语言 > 详细

SpringBoot2.2.2 中 jpa Repository的findOne 正确写法 和 findAll

时间:2020-01-08 15:29:40      阅读:463      评论:0      收藏:0      [点我收藏+]

 


@GetMapping("/user/{id}")
public User getUser(@PathVariable("id") Integer id) {
User user = new User();
user.setId(id);
Example<User> example = Example.of(user);
Optional<User> one = userRepository.findOne(example);
return one.get();
}

@GetMapping("/user/all")
public List<User> getAll() {
List<User> all = userRepository.findAll();
System.out.println(all);
return all;
}

SpringBoot2.2.2 中 jpa Repository的findOne 正确写法 和 findAll

原文:https://www.cnblogs.com/wf-zhang/p/12166197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!