1、分页查询
@Override
public PaginationBean<实体> getCodeList(String code, Pagination page)
throws Exception {
StringBuilder hql = new StringBuilder(" from 实体 t where 1 = 1 ");
Map<String, Object> paramList = new HashMap<String, Object>();
//判断查询条件是否为空
if (StringUtils.isNotEmpty(pumpCode)) {
hql.append(" and t.code = '"+code+"' ");
}
hql.append(" order by t.createTime desc ");
return this.findAll(page, hql.toString(), paramList);
}
2、不分页查询
@Override
public List<实体> exportExcel(String code) {
StringBuilder hql = new StringBuilder(" from 实体 t where 1 = 1 ");
Map<String, Object> paramList = new HashMap<String, Object>();
if (StringUtils.isNotEmpty(code)) {
hql.append(" and t.code = '"+code+"' ");
}
hql.append(" order by t.createTime desc ");
TypedQuery<实体> query = getEntityManager().createQuery(hql.toString(), 实体.class);
this.setParameterList(query, paramList);
List<实体> resultList = query.getResultList();
return resultList;
}