}
/** * 构造where子句 * @param condition 查询条件语句;例如:i.title like ? * @param params 查询条件语句中?对应的查询条件值;例如: %标题% */ public HqlHelper addWhereCondition(String condition, Object... params) { if (whereClause.length() == 0) { whereClause = " WHERE " + condition; } else { whereClause += " AND " + condition; } if (params != null && params.length > 0) { for (Object param : params) { this.parameters.add(param); } } return this; } /** * 如果第一个参数为true,则拼接Where子句(添加的多个过滤条件之间是使用AND连接的) * * @param append 为true 添加条件 * @param condition * 一个过滤条件 * @param params */ public HqlHelper addWhereCondition(boolean append, String condition, Object... params) { if (append) { addWhereCondition(condition, params); } return this; } /** * 拼接OrderBy子句 * * @param propertyName * @param isAsc */ public HqlHelper addOrderByProperty(String propertyName, boolean isAsc) { if (orderByClause.length() == 0) { orderByClause = " ORDER BY " + propertyName + (isAsc ? " ASC" : " DESC"); } else { orderByClause += ", " + propertyName + (isAsc ? " ASC" : " DESC"); } return this; } /** * 如果第一个参数为true,则拼接OrderBy子句 * * @param propertyName * @param isAsc */ public HqlHelper addOrderByProperty(boolean append, String propertyName, boolean isAsc) { if (append) { addOrderByProperty(propertyName, isAsc); } return this; } /** * 获取查询数据列表的的HQL语句 * * @return */ public String getQueryListHql() { return selectClause + fromClause + whereClause + orderByClause; } /** * 获取查询总记录数的的HQL语句 * * @return */ public String getQueryCountHql() { return "SELECT COUNT(*) " + fromClause + whereClause; } /** * 获取参数列表 * * @return */ public List<Object> getParameters() { return parameters; } }
