Skip to content

Commit

Permalink
Add method removeEqual to Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Aug 23, 2014
1 parent d14ac90 commit 359b490
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/xiaoleilu/hutool/db/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map.Entry;

import com.xiaoleilu.hutool.Conver;
import com.xiaoleilu.hutool.InjectUtil;
Expand Down Expand Up @@ -106,6 +107,21 @@ public Entity parse(Object vo) {
return this;
}

/**
* 与给定实体对比并去除相同的部分<br>
* 此方法用于在更新操作时避免所有字段被更新,跳过不需要更新的字段
* version from 2.0.0
* @param entity
*/
public <T extends Entity> void removeEqual(T entity) {
for(Entry<String, Object> entry : entity.entrySet()) {
final Object value = this.get(entry.getKey());
if(null != value && value.equals(entry.getValue())) {
this.remove(entry.getKey());
}
}
}

//-------------------------------------------------------------------- 特定类型值
/**
* 设置列
Expand Down

0 comments on commit 359b490

Please sign in to comment.