Spring REST partial update with @PATCH method

后端 未结 4 1976
感动是毒
感动是毒 2021-01-31 12:47

I\'m trying to implement a partial update of the Manager entity based in the following:

Entity

public class Manager {
    private int id;
    private Str         


        
4条回答
  •  悲&欢浪女
    2021-01-31 13:10

    You can write custom update query which updates only particular fields:

    @Override
    public void saveManager(Manager manager) {  
        Query query = sessionFactory.getCurrentSession().createQuery("update Manager set username = :username, password = :password where id = :id");
        query.setParameter("username", manager.getUsername());
        query.setParameter("password", manager.getPassword());
        query.setParameter("id", manager.getId());
        query.executeUpdate();
    }
    

提交回复
热议问题