不正确的: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;