actframework / act-ebean

The ebean plugin that uses latest ebeanorm and requrie java 8 support
Apache License 2.0
2 stars 1 forks source link

Can add saveOrUpdate method in EbeanDao? #14

Open thetcc opened 7 years ago

thetcc commented 7 years ago

like this:

    @PostAction("/save")
    public void update(User user) {
        ebeanDao.saveOrUpdate(user);
        // if user.id == null, insert user to database.
        // if user.id != null,update user fields(not null) by user.id,if user.name is null,don't update user.name
    }
    @PostAction("/save")
    public void update(User user) {
        //now, i have to do like this:
        User u = ebeanDao.getById(user.id);
        if(user.name!=null){
            u.name = user.name;
        }
        if(user.age!=null){
            u.age = user.age;
        }
        // ... if user has other fields
        ebeanDao.save(u);
    }