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(); }
原文:https://www.cnblogs.com/zxf330301/p/9508749.html