NutzCN Logo
问答 string类型数据,设置sql查询条件时这个string有值或者为null,具体请看下面例子
发布于 3201天前 作者 fwm520 2460 次浏览 复制 上一个帖子 下一个帖子
标签:

不正确的:WHERE id>0 AND city_code='GUANGZHOU' OR city_code IS NULL AND type=7 AND status IN (0,1) ORDER BY createDate DESC
我想要的结果:WHERE id>0 AND (city_code='GUANGZHOU' OR city_code IS NULL) AND type=7 AND status IN (0,1) ORDER BY createDate DESC
就是city_code的条件用括号括起来。
下面是代码,我想问如何修改下面的代码才能有那个括号啊**

Cnd cnd = Cnd.where("id", ">", 0);
if (shop != null) {
if ((!StringUtils.isEmpty(shop.getCityCode()))) {
if(shop.getCityCode().equals("GUANGZHOU")){
cnd.where().and("city_code", "=",shop.getCityCode()).orIsNull("city_code");
}else{
cnd.and("city_code", "=", shop.getCityCode());}
}
if (!Strings.isEmpty(shop.getName())) {
cnd.and("name", "like", "%" + shop.getName().trim() + "%");
}
if (shop.getUuid() > 0) {
cnd.and("uuid", "=", shop.getUuid());
}
if (shop.getType() > 0) {
cnd.and("type", "=", shop.getType());
}else{
cnd.and("type", "=", 7);
}
if (shop.getCatId() > 0) {
cnd.and("catId", "=", shop.getCatId());
}
if (date != null) {
if (date.getStartDate() != null) {
cnd.and("createDate", ">=", date.getStartDate());
}
if (date.getEndDate() != null) {
cnd.and("createDate", "<=", date.getEndDate());
}
}
}
int[] status = { 0, 1 }; // 只查询停用启用状态的店铺
cnd.where().andInIntArray("status", status);
cnd.desc("createDate");
return cnd;

2 回复

@wendal 嗯,对,就是这个,谢了教授

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