SpringBoot2.2.2 中 jpa Repository的findOne 正确写法 和 findAll
时间:2020-01-08 15:29:40
收藏:0
阅读:463
@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;
}
原文:https://www.cnblogs.com/wf-zhang/p/12166197.html
评论(0)