没看上篇博客的请查看XUtil学习之DBUtil(九)
改
(1)update(Object entity, String… updateColumnNames)
更新特定行的数据
public void update(Object entity, String... updateColumnNames) throws DbException {
if (!tableIsExist(entity.getClass())) return;
try {
beginTransaction();
execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, updateColumnNames));
setTransactionSuccessful();
} finally {
endTransaction();
}
}
(2)update(Object entity, WhereBuilder whereBuilder, String… updateColumnNames)
按特定条件更新数据
public void update(Object entity, WhereBuilder whereBuilder, String... updateColumnNames) throws DbException {
if (!tableIsExist(entity.getClass())) return;
try {
beginTransaction();
execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, whereBuilder, updateColumnNames));
setTransactionSuccessful();
} finally {
endTransaction();
}
}
(3)updateAll(List< > entities, String… updateColumnNames)
更新集合中所有的数据
public void updateAll(List<?> entities, String... updateColumnNames) throws DbException {
if (entities == null || entities.size() == 0 || !tableIsExist(entities.get(0).getClass())) return;
try {
beginTransaction();
for (Object entity : entities) {
execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, updateColumnNames));
}
setTransactionSuccessful();
} finally {
endTransaction();
}
}
(4)updateAll(List< > entities, WhereBuilder whereBuilder, String… updateColumnNames)
更新集合中所有满足条件的数据
public void updateAll(List<?> entities, WhereBuilder whereBuilder, String... updateColumnNames) throws DbException {
if (entities == null || entities.size() == 0 || !tableIsExist(entities.get(0).getClass())) return;
try {
beginTransaction();
for (Object entity : entities) {
execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, whereBuilder, updateColumnNames));
}
setTransactionSuccessful();
} finally {
endTransaction();
}
}

本文详细介绍了XUtil库中的DBUtil模块针对不同场景下的更新操作方法,包括单条记录更新、批量更新及带有条件的更新等。通过具体代码示例展示了如何使用这些方法来高效地更新数据库中的数据。
687

被折叠的 条评论
为什么被折叠?



