代码如下:
String jpql = "select a from DeliverychargesItem a where 1=1";
List params = new ArrayList();
if (condition.get("companyCode") != null) {
jpql += " and a.company.companyCode = ? ";
params.add(condition.get("companyCode"));
}
if (condition.get("companyName") != null) {
jpql += " and a.company.companyName = ? ";
params.add(condition.get("companyName"));
}
if (condition.get("payDate") != null) {
jpql += " and CONCAT(cast(YEAR(payDate) as string),cast(MONTH(payDate) as string)) = ? ";
params.add(condition.get("payDate"));
}
List list = this.findPageList(jpql, params.toArray(), index, length);
return list;
记下两点:1.hql的cast 转换的类型不是数据库中的类型而是java中的(int, String...)
2.如上代码 类型名写为String会报错,改为string才OK,估计是必须写为小写。