NutzCN Logo
问答 dao操作中不用自己写sql,如何加去除null值的条件
发布于 2437天前 作者 DarkObject 1877 次浏览 复制 上一个帖子 下一个帖子
标签:

用的oracle数据库,在dao操作中不用自己写sql,如何加去除null值的条件

26 回复

Cnd有andEX和orEX方法

andEX("is", "not", "null")这是直接在sql后边拼接的字符串,日志打印语句出错
"SELECT * FROM table WHERE id='1' AND is NOT 'null'"

你这是写啥??????

去除一行记录中为null的值

只查出这一行中有数据的值

用法跟and一样的

Cnd.where("name", "=", "wendal").andEX("location", '!=", location);

比如有表tb 表内容是 1 2 3 4 5 (NULL) (NULL) (NULL) ...... (一条记录)
我用select * from tb 取过来的值就把这些空值(NULL)也取过来了 我想要自动舍弃空值 比如例子中就取到 1 2 3 4 5 这里结束 sql语句条件要怎么加?

你指的空值是数据库里面的啊? 我还以为是条件呢

Cnd.where("name", "is not", null);

我是要查出这一行的记录,去掉为null的值,只要有数据的值
假如有表
name age sex salary
aa null 1 null
我要查出来的数据是 name : aa sex : 1 其他没值的不要

这样有什么意义?

要根据查出来的数据决定在页面都显示什么内容,我想每次直接查出来的数据里面不包含空值,这样就不用再写判断 语句了

那返回数据给页面的时候忽略空值就好啦,如果是ajax的话

@Ok("json:{ignoreNull:true}") 这样可以吗?

不行啊,这个忽略不了

输出的json贴来看看

{
"id": "4",
"name": "ddd",
"type": "type4",
"parentCategoryid": "1",
"categoryUrl": "xxx",
"createAt": 1111,
"updateAt": 2222,
"unitId": "007",
"coordinateSystem": "wgs84",
"descinfo": "9999",
"metadataid": "1",
"disable": "0",
"delflag": "0",
"resourceMetadate": {
"id": "1",
"count": 3,
"descinfo": "11111",
"createAt": 1102,
"templateId": "1",
"item1": "x1",
"item2": "x2",
"item3": "x3",
"item4": null,
"item5": null,
"item6": null,
"item7": null,
"item8": null,
"item9": null,
"item10": null,
"item11": null,
"item12": null,
"item13": null,
"item14": null,
"item15": null,
"item16": null,
"item17": null,
"item18": null,
"item19": null,
"item20": null,
"metadataModel": {
"id": "1",
"count": 3,
"createUnitid": null,
"createAt": 0,
"responsableperson": null,
"descinfo": null,
"item1": "xx1",
"item2": "xx2",
"item3": "xx3",
"item4": null,
"item5": null,
"item6": null,
"item7": null,
"item8": null,
"item9": null,
"item10": null,
"item11": null,
"item12": null,
"item13": null,
"item14": null,
"item15": null,
"item16": null,
"item17": null,
"item18": null,
"item19": null,
"item20": null
}
}
}

入口方法贴来看看

@At("/showTree")
@Ok("json:{ignoreNull:true}")
public Object tree(@Param("pid") String pid) {
if(Strings.isBlank(pid)){
pid = "0";
}
List list = resourceService.query(Cnd.where("parentCategoryid", "=", pid));
List<Map<String, Object>> tree = new ArrayList<>();
Map<String, Object> obj = new HashMap<>();
for (ResourceDefine unit : list) {
obj = new HashMap<>();
obj.put("id", unit.getId());
obj.put("text", unit.getName());
obj.put("children", true);
tree.add(obj);
}
return tree;
}

}

我把@Ok("json:{ignoreNull:true}")加错地方了,,,,,,,请求数据的入口函数上还是@ok("json")
我换了@Ok("json:{ignoreNull:true}")之后会 忽略掉null值
................还是对nutz的注解和基本操作不太熟啊!!!

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