How do I update an entity using spring-data-jpa?

后端 未结 10 1879
眼角桃花
眼角桃花 2020-11-29 15:12

Well the question pretty much says everything. Using JPARepository how do I update an entity?

JPARepository has only a save method, which does not t

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 15:30

    This is how I solved the problem:

    User inbound = ...
    User existing = userRepository.findByFirstname(inbound.getFirstname());
    if(existing != null) inbound.setId(existing.getId());
    userRepository.save(inbound);
    

提交回复
热议问题