NutzCN Logo
问答 关于dao 过滤去的一个业务需求
发布于 3053天前 作者 Rekoe 2697 次浏览 复制 上一个帖子 下一个帖子
标签: dao

在调用 更新

FieldFilter filter = FieldFilter.create(entity.getClass(), FieldMatcher.make(null, fieldsIgnore, true));
Daos.ext(dao, filter, getSplitTableId(pid)).updateIgnoreNull(entity);

如果这个对象没有任何可以更新的字段的时候
会出现 update xxx_table where id='xxx' 的错误sql
能否在更新的时候检查选 如果是这样的情况下就跳过更新操作

8 回复

我想想有什么办法

来自炫酷的 NutzCN

daocache 那层是不是可以获得 一些信息
@wendal

@wendal
看到更新的 时候有这个日志

2015-12-11 13:38:58,399 [DEBUG][org.nutz.dao.util.Pojos] - none field for update!

我这样做了下判断

FieldFilter filter = FieldFilter.create(entity.getClass(), FieldMatcher.make(null, "^(name|id|sex)", true));
Collection<FieldMatcher> fms = filter.map().values();
for (FieldMatcher fm : fms) {
	List<MappingField> mfList = Pojos.getFieldsForUpdate(dao.getEntity(getEntityClass()), fm, entity);
	if (Lang.isEmpty(mfList)) {
		continue;
	}
	isRight = true;
	break;
}
if (isRight) {
int t = Daos.ext(dao, filter).update(entity);
}

应该是这样吧


FieldMatcher fm = FieldMatcher.make(null, "^(name|id|sex)", true); if (Lang.isEmpty(Pojos.getFieldsForUpdate(entity, fm, obj))) return; return Daos.ext(dao, FieldFilter.create(getEntityClass(), true)).update(entity);

还是错了


FieldMatcher fm = FieldMatcher.make(null, "^(name|id|sex)", true); if (Lang.isEmpty(Pojos.getFieldsForUpdate(entity, fm, obj))) return; return Daos.ext(dao, FieldFilter.create(obj.getClass(), true)).update(obj);

暂时就这样解决的

添加回复
请先登陆
回到顶部