<T> List<T> queryByJoin(Class<T> var1, String var2, Condition var3, Pager var4);
<T> List<T> queryByJoin(Class<T> var1, String var2, Condition var3, Pager var4, Map<String, Condition> var5);
<T> int countByJoin(Class<T> var1, String var2, Condition var3);
目前使用queryByJoin如下所示
@CacheResult
public List<Food_detect_data> data (NutMap nutMap) {
Cnd cnd = Cnd.NEW();
//检测项目
String testItemIds = nutMap.getString("testItemId[]");
if(testItemIds!=null) {
cnd.and("testItemId", "in", testItemIds);
}
//检测地区
Map<String, Condition> map = new HashMap<String, Condition>();
Integer districtId = nutMap.getInt("districtId");
if(districtId!=null&&districtId>0) {
map.put("market", Cnd.NEW().where("districtId", "=", districtId));
}
//检测类别
Integer detectKind = nutMap.getInt("detectKind");
if(detectKind!=null&&detectKind>0) {
cnd.and("detectKind", "=", detectKind);
}
//检测单位
String unitId = nutMap.getString("unitId");
if(unitId!=null) {
cnd.and("unitId", "=", unitId);
}
//时间段筛选
String[] detectDate = nutMap.getArray("detectDate[]", String.class);
if(detectDate!=null) {
SqlExpressionGroup c = Cnd.exps(new Static("detectDate between '"+detectDate[0]+"' and '"+detectDate[1]+"'"))
.or("detectDate", "like", detectDate[1]+"%");
cnd.and(c);
}
//消费者送检
Integer isConsumerSent = nutMap.getInt("isConsumerSent");
if(isConsumerSent!=null&&isConsumerSent>0) {
cnd.and("isConsumerSent", "=", isConsumerSent);
}
//食品分类
String[] parent = StringUtils.split(nutMap.getString("parent[]"), ",");
if(parent !=null) {
if(parent.length == 3) {
cnd.and("kindId", "=", Integer.parseInt(parent[2]));
}else if(parent.length == 2) {
cnd.and("smallKindId", "=", Integer.parseInt(parent[1]));
}else if(parent.length == 1) {
cnd.and("bigKindId", "=", Integer.parseInt(parent[0]));
}
}
//样品编号
String sn = nutMap.getString("sn");
if(sn!=null) {
cnd.and("sn", "like", "%"+sn+"%");
}
//检测结果
Integer detectResult = nutMap.getInt("detectResult");
if(detectResult!=null&&detectResult>0) {
cnd.and("detectResult", "=", detectResult);
}
//被检单位
String byDetectUnit = nutMap.getString("byDetectUnit");
if(sn!=null) {
cnd.and("byDetectUnit", "like", "%"+byDetectUnit+"%");
}
Pager pager = new Pager(nutMap.getInt("pageNumber"), nutMap.getInt("pageSize"));
cnd.orderBy("detectDate", "desc");
return dao().queryByJoin(Food_detect_data.class, "^(unit|smallKind|kind|testItem|testStandard|market)$", cnd, pager, map);
}
其中countByJoin没有Map<String, Condition> 参数,所以没有办法获得总数……还是要写SQL啊