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


@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;
}

猜你喜欢

转载自www.cnblogs.com/wf-zhang/p/12166197.html