1.javabean的屬性值生成sql
/** * 獲取所有查詢列,如id,name,code... * * @param entityClass * @return */ public static String getAllColumns(Class<?> entityClass) { Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass); StringBuilder sql = new StringBuilder(); for (EntityColumn entityColumn : columnSet) { sql.append(entityColumn.getColumn()).append(","); } return sql.substring(0, sql.length() - 1); }
/** * 判斷自動==null的條件結構 * * @param entityName * @param column * @param contents * @param empty * @return */ public static String getIfIsNull(String entityName, EntityColumn column, String contents, boolean empty) { StringBuilder sql = new StringBuilder(); sql.append("<if test=\""); if (StringUtil.isNotEmpty(entityName)) { sql.append(entityName).append("."); } sql.append(column.getProperty()).append(" == null"); if (empty && column.getJavaType().equals(String.class)) { sql.append(" or "); if (StringUtil.isNotEmpty(entityName)) { sql.append(entityName).append("."); } sql.append(column.getProperty()).append(" == '' "); } sql.append("\">"); sql.append(contents); sql.append("</if>"); return sql.toString(); }