大家帮看看这种 Java 写 sql 的代码可取吗
資深大佬 : madworks 2
@Override public DataListPage
String mainStoreId = BusinessUtils.getMainStoreId(branchStoreId); String listHql = CONSTRUCTOR + " FROM TCmsLesson cl, TCmsLessonStoreRel r" + " WHERE cl.firstClass = :firstClass" + " AND cl.isValid = 1" + " AND cl.id = r.lessonId" + " AND r.storeId in (:mainStoreId , :branchStoreId , '0000000')"; String countHql = "SELECT COUNT(cl.id) FROM" + " TCmsLesson cl, TCmsLessonStoreRel r" + " WHERE cl.firstClass = :firstClass" + " AND cl.isValid = 1" + " AND cl.id = r.lessonId" + " AND r.storeId in (:mainStoreId , :branchStoreId , '0000000')"; dataListParams.setDateParam("cl.createDate"); return super.getDataListPageByHql(listHql, countHql, dataListParams, firstClass, mainStoreId, branchStoreId); } private List<T> listDataByHql(String hql, DataListParams dataListParams, Object... values) { if (StringUtils.isNotEmpty(dataListParams.getBeginTime()) && StringUtils.isNotEmpty(dataListParams.getEndTime())) { hql = hql + " AND " + dataListParams.getDateParam() + " BETWEEN '" + dataListParams.getBeginTime() + "' AND '" + dataListParams.getEndTime() + "'"; } else if (StringUtils.isNotEmpty(dataListParams.getBeginTime())) { hql = hql + " AND " + dataListParams.getDateParam() + " >= '" + dataListParams.getBeginTime() + "'"; } else if (StringUtils.isNotEmpty(dataListParams.getEndTime())) { hql = hql + " AND " + dataListParams.getDateParam() + " <= '" + dataListParams.getEndTime() + "'"; } if (StringUtils.isNotEmpty(dataListParams.getOrderBy())) { hql = hql + " ORDER BY " + dataListParams.getOrderBy(); } if (dataListParams.isDesc()) { hql = hql + " DESC"; } if (dataListParams.getPage() != null) { return this.listByPage(hql, dataListParams.getPage(), values); } else { return dataListParams.getSize() == 0 ? this.listByParamsAndPosition(hql, dataListParams.getStartPosition(), values) : this.listBySizeAndPosition(hql, dataListParams.getSize(), dataListParams.getStartPosition(), values); } }
大佬有話說 (33)