Java Code Examples for tk.mybatis.mapper.util.StringUtil#isNotEmpty()
The following examples show how to use
tk.mybatis.mapper.util.StringUtil#isNotEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultEntityResolve.java From Mapper with MIT License | 6 votes |
/** * 处理排序 * * @param entityTable * @param field * @param entityColumn */ protected void processOrderBy(EntityTable entityTable, EntityField field, EntityColumn entityColumn) { String orderBy = ""; if(field.isAnnotationPresent(OrderBy.class)){ orderBy = field.getAnnotation(OrderBy.class).value(); if ("".equals(orderBy)) { orderBy = "ASC"; } log.warn(OrderBy.class + " is outdated, use " + Order.class + " instead!"); } if (field.isAnnotationPresent(Order.class)) { Order order = field.getAnnotation(Order.class); if ("".equals(order.value()) && "".equals(orderBy)) { orderBy = "ASC"; } else { orderBy = order.value(); } entityColumn.setOrderPriority(order.priority()); } if (StringUtil.isNotEmpty(orderBy)) { entityColumn.setOrderBy(orderBy); } }
Example 2
Source File: SqlHelper.java From Mapper with MIT License | 6 votes |
/** * 判断自动!=null的条件结构 * * @param entityName * @param column * @param contents * @param empty * @return */ public static String getIfNotNull(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(" and "); if (StringUtil.isNotEmpty(entityName)) { sql.append(entityName).append("."); } sql.append(column.getProperty()).append(" != '' "); } sql.append("\">"); sql.append(contents); sql.append("</if>"); return sql.toString(); }
Example 3
Source File: MapperHelper.java From tk-mybatis with MIT License | 6 votes |
/** * 配置属性 * * @param properties */ public void setProperties(Properties properties) { config.setProperties(properties); //注册通用接口 String mapper = null; if (properties != null) { mapper = properties.getProperty("mappers"); } if (StringUtil.isNotEmpty(mapper)) { String[] mappers = mapper.split(","); for (String mapperClass : mappers) { if (mapperClass.length() > 0) { registerMapper(mapperClass); } } } }
Example 4
Source File: SqlHelper.java From tk-mybatis with MIT License | 6 votes |
/** * 获取表名 - 支持动态表名,该方法用于多个入参时,通过parameterName指定入参中实体类的@Param的注解值 * * @param entityClass * @param tableName * @param parameterName * @return */ public static String getDynamicTableName(Class<?> entityClass, String tableName, String parameterName) { if (IDynamicTableName.class.isAssignableFrom(entityClass)) { if (StringUtil.isNotEmpty(parameterName)) { return "<if test=\"@tk.mybatis.mapper.util.OGNL@isDynamicParameter(" + parameterName + ") and " + parameterName + ".dynamicTableName != null and " + parameterName + ".dynamicTableName != ''\">\n" + "${" + parameterName + ".dynamicTableName}\n" + "</if>\n" + "<if test=\"@tk.mybatis.mapper.util.OGNL@isNotDynamicParameter(" + parameterName + ") or " + parameterName + ".dynamicTableName == null or " + parameterName + ".dynamicTableName == ''\">\n" + tableName + "\n" + "</if>"; } else { return getDynamicTableName(entityClass, tableName); } } else { return tableName; } }
Example 5
Source File: SqlHelper.java From tk-mybatis with MIT License | 6 votes |
/** * 判断自动!=null的条件结构 * * @param entityName * @param column * @param contents * @param empty * @return */ public static String getIfNotNull(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(" and "); if (StringUtil.isNotEmpty(entityName)) { sql.append(entityName).append("."); } sql.append(column.getProperty()).append(" != '' "); } sql.append("\">"); sql.append(contents); sql.append("</if>"); return sql.toString(); }
Example 6
Source File: SqlHelper.java From Mapper with MIT License | 6 votes |
/** * 获取表名 - 支持动态表名,该方法用于多个入参时,通过parameterName指定入参中实体类的@Param的注解值 * * @param entityClass * @param tableName * @param parameterName * @return */ public static String getDynamicTableName(Class<?> entityClass, String tableName, String parameterName) { if (IDynamicTableName.class.isAssignableFrom(entityClass)) { if (StringUtil.isNotEmpty(parameterName)) { StringBuilder sql = new StringBuilder(); sql.append("<choose>"); sql.append("<when test=\"@tk.mybatis.mapper.util.OGNL@isDynamicParameter(" + parameterName + ") and " + parameterName + ".dynamicTableName != null and " + parameterName + ".dynamicTableName != ''\">"); sql.append("${" + parameterName + ".dynamicTableName}"); sql.append("</when>"); //不支持指定列的时候查询全部列 sql.append("<otherwise>"); sql.append(tableName); sql.append("</otherwise>"); sql.append("</choose>"); return sql.toString(); } else { return getDynamicTableName(entityClass, tableName); } } else { return tableName; } }
Example 7
Source File: Config.java From Mapper with MIT License | 5 votes |
/** * 获取表前缀,带catalog或schema * * @return */ public String getPrefix() { if (StringUtil.isNotEmpty(this.catalog)) { return this.catalog; } if (StringUtil.isNotEmpty(this.schema)) { return this.schema; } return ""; }
Example 8
Source File: Example.java From tk-mybatis with MIT License | 5 votes |
public OrderBy orderBy(String property) { String column = property(property); if (column == null) { isProperty = false; return this; } if (StringUtil.isNotEmpty(example.getOrderByClause())) { example.setOrderByClause(example.getOrderByClause() + "," + column); } else { example.setOrderByClause(column); } isProperty = true; return this; }
Example 9
Source File: Config.java From Mapper with MIT License | 5 votes |
/** * 获取主键自增回写SQL * * @return */ public String getIDENTITY() { if (StringUtil.isNotEmpty(this.IDENTITY)) { return this.IDENTITY; } //针对mysql的默认值 return IdentityDialect.MYSQL.getIdentityRetrievalStatement(); }
Example 10
Source File: EntityColumn.java From Mapper with MIT License | 5 votes |
/** * 返回格式如:#{entityName.age+suffix,jdbcType=NUMERIC,typeHandler=MyTypeHandler}+separator * * @param entityName * @param suffix * @param separator * @return */ public String getColumnHolder(String entityName, String suffix, String separator) { StringBuffer sb = new StringBuffer("#{"); if (StringUtil.isNotEmpty(entityName)) { sb.append(entityName); sb.append("."); } sb.append(this.property); if (StringUtil.isNotEmpty(suffix)) { sb.append(suffix); } //如果 null 被当作值来传递,对于所有可能为空的列,JDBC Type 是需要的 if (this.jdbcType != null) { sb.append(", jdbcType="); sb.append(this.jdbcType.toString()); } //为了以后定制类型处理方式,你也可以指定一个特殊的类型处理器类,例如枚举 if (this.typeHandler != null) { sb.append(", typeHandler="); sb.append(this.typeHandler.getCanonicalName()); } //3.4.0 以前的 mybatis 无法获取父类中泛型的 javaType,所以如果使用低版本,就需要设置 useJavaType = true //useJavaType 默认 false,没有 javaType 限制时,对 ByPrimaryKey 方法的参数校验就放宽了,会自动转型 if (useJavaType && !this.javaType.isArray()) {//当类型为数组时,不设置javaType#103 sb.append(", javaType="); sb.append(javaType.getCanonicalName()); } sb.append("}"); if (StringUtil.isNotEmpty(separator)) { sb.append(separator); } return sb.toString(); }
Example 11
Source File: Example.java From Mapper with MIT License | 5 votes |
public OrderBy orderBy(String property) { String column = property(property); if (column == null) { isProperty = false; return this; } if (StringUtil.isNotEmpty(example.getOrderByClause())) { example.setOrderByClause(example.getOrderByClause() + "," + column); } else { example.setOrderByClause(column); } isProperty = true; return this; }
Example 12
Source File: AggregateCondition.java From Mapper with MIT License | 5 votes |
/** * @param aggregateProperty 不能为空,为保证返回结果key与传入值相同 方法不会去除前后空格 * @param aggregateType * @param groupByProperties 为保证返回结果key与传入值相同 方法不会去除每一项前后空格 */ public AggregateCondition(String aggregateProperty, AggregateType aggregateType, String[] groupByProperties) { this.groupByProperties = new ArrayList<String>(); // 需要放在propertyMap初始化完成后执行 aggregateType(aggregateType); if (StringUtil.isNotEmpty(aggregateProperty)) { aggregateBy(aggregateProperty); } groupBy(groupByProperties); }
Example 13
Source File: EntityTable.java From tk-mybatis with MIT License | 5 votes |
public String getPrefix() { if (StringUtil.isNotEmpty(catalog)) { return catalog; } if (StringUtil.isNotEmpty(schema)) { return schema; } return ""; }
Example 14
Source File: EntityTable.java From Mapper with MIT License | 5 votes |
public String getPrefix() { if (StringUtil.isNotEmpty(catalog)) { return catalog; } if (StringUtil.isNotEmpty(schema)) { return schema; } return ""; }
Example 15
Source File: Config.java From tk-mybatis with MIT License | 5 votes |
/** * 获取序列格式化模板 * * @return */ public String getSeqFormat() { if (StringUtil.isNotEmpty(this.seqFormat)) { return this.seqFormat; } return "{0}.nextval"; }
Example 16
Source File: Config.java From tk-mybatis with MIT License | 5 votes |
/** * 获取主键自增回写SQL * * @return */ public String getIDENTITY() { if (StringUtil.isNotEmpty(this.IDENTITY)) { return this.IDENTITY; } //针对mysql的默认值 return IdentityDialect.MYSQL.getIdentityRetrievalStatement(); }
Example 17
Source File: EntityColumn.java From tk-mybatis with MIT License | 5 votes |
/** * 返回格式如:#{entityName.age+suffix,jdbcType=NUMERIC,typeHandler=MyTypeHandler}+separator * * @param entityName * @param suffix * @param separator * @return */ public String getColumnHolder(String entityName, String suffix, String separator) { StringBuffer sb = new StringBuffer("#{"); if (StringUtil.isNotEmpty(entityName)) { sb.append(entityName); sb.append("."); } sb.append(this.property); if (StringUtil.isNotEmpty(suffix)) { sb.append(suffix); } if (this.jdbcType != null) { sb.append(",jdbcType="); sb.append(this.jdbcType.toString()); } else if (this.typeHandler != null) { sb.append(",typeHandler="); sb.append(this.typeHandler.getCanonicalName()); } else if (!this.javaType.isArray()) {//当类型为数组时,不设置javaType#103 sb.append(",javaType="); sb.append(javaType.getCanonicalName()); } sb.append("}"); if (StringUtil.isNotEmpty(separator)) { sb.append(separator); } return sb.toString(); }
Example 18
Source File: Config.java From Mapper with MIT License | 4 votes |
/** * 配置属性 * * @param properties */ public void setProperties(Properties properties) { if (properties == null) { //默认驼峰 this.style = Style.camelhump; return; } String IDENTITY = properties.getProperty("IDENTITY"); if (StringUtil.isNotEmpty(IDENTITY)) { setIDENTITY(IDENTITY); } String seqFormat = properties.getProperty("seqFormat"); if (StringUtil.isNotEmpty(seqFormat)) { setSeqFormat(seqFormat); } String catalog = properties.getProperty("catalog"); if (StringUtil.isNotEmpty(catalog)) { setCatalog(catalog); } String schema = properties.getProperty("schema"); if (StringUtil.isNotEmpty(schema)) { setSchema(schema); } //ORDER 有三个属性名可以进行配置 String ORDER = properties.getProperty("ORDER"); if (StringUtil.isNotEmpty(ORDER)) { setOrder(ORDER); } ORDER = properties.getProperty("order"); if (StringUtil.isNotEmpty(ORDER)) { setOrder(ORDER); } ORDER = properties.getProperty("before"); if (StringUtil.isNotEmpty(ORDER)) { setBefore(Boolean.valueOf(ORDER)); } this.notEmpty = Boolean.valueOf(properties.getProperty("notEmpty")); this.enableMethodAnnotation = Boolean.valueOf(properties.getProperty("enableMethodAnnotation")); this.checkExampleEntityClass = Boolean.valueOf(properties.getProperty("checkExampleEntityClass")); //默认值 true,所以要特殊判断 String useSimpleTypeStr = properties.getProperty("useSimpleType"); if (StringUtil.isNotEmpty(useSimpleTypeStr)) { this.useSimpleType = Boolean.valueOf(useSimpleTypeStr); } this.enumAsSimpleType = Boolean.valueOf(properties.getProperty("enumAsSimpleType")); //注册新的基本类型,以逗号隔开,使用全限定类名 String simpleTypes = properties.getProperty("simpleTypes"); if (StringUtil.isNotEmpty(simpleTypes)) { SimpleTypeUtil.registerSimpleType(simpleTypes); } //使用 8 种基本类型 if (Boolean.valueOf(properties.getProperty("usePrimitiveType"))) { SimpleTypeUtil.registerPrimitiveTypes(); } String styleStr = properties.getProperty("style"); if (StringUtil.isNotEmpty(styleStr)) { try { this.style = Style.valueOf(styleStr); } catch (IllegalArgumentException e) { throw new MapperException(styleStr + "不是合法的Style值!"); } } else { //默认驼峰 this.style = Style.camelhump; } //处理关键字 String wrapKeyword = properties.getProperty("wrapKeyword"); if (StringUtil.isNotEmpty(wrapKeyword)) { this.wrapKeyword = wrapKeyword; } //安全删除 this.safeDelete = Boolean.valueOf(properties.getProperty("safeDelete")); //安全更新 this.safeUpdate = Boolean.valueOf(properties.getProperty("safeUpdate")); //是否设置 javaType,true 时如 {id, javaType=java.lang.Long} this.useJavaType = Boolean.valueOf(properties.getProperty("useJavaType")); }
Example 19
Source File: DefaultEntityResolve.java From Mapper with MIT License | 4 votes |
/** * 处理字段 * * @param entityTable * @param field * @param config * @param style */ protected void processField(EntityTable entityTable, EntityField field, Config config, Style style) { //排除字段 if (field.isAnnotationPresent(Transient.class)) { return; } //Id EntityColumn entityColumn = new EntityColumn(entityTable); //是否使用 {xx, javaType=xxx} entityColumn.setUseJavaType(config.isUseJavaType()); //记录 field 信息,方便后续扩展使用 entityColumn.setEntityField(field); if (field.isAnnotationPresent(Id.class)) { entityColumn.setId(true); } //Column String columnName = null; if (field.isAnnotationPresent(Column.class)) { Column column = field.getAnnotation(Column.class); columnName = column.name(); entityColumn.setUpdatable(column.updatable()); entityColumn.setInsertable(column.insertable()); } //ColumnType if (field.isAnnotationPresent(ColumnType.class)) { ColumnType columnType = field.getAnnotation(ColumnType.class); //是否为 blob 字段 entityColumn.setBlob(columnType.isBlob()); //column可以起到别名的作用 if (StringUtil.isEmpty(columnName) && StringUtil.isNotEmpty(columnType.column())) { columnName = columnType.column(); } if (columnType.jdbcType() != JdbcType.UNDEFINED) { entityColumn.setJdbcType(columnType.jdbcType()); } if (columnType.typeHandler() != UnknownTypeHandler.class) { entityColumn.setTypeHandler(columnType.typeHandler()); } } //列名 if (StringUtil.isEmpty(columnName)) { columnName = StringUtil.convertByStyle(field.getName(), style); } //自动处理关键字 if (StringUtil.isNotEmpty(config.getWrapKeyword()) && SqlReservedWords.containsWord(columnName)) { columnName = MessageFormat.format(config.getWrapKeyword(), columnName); } entityColumn.setProperty(field.getName()); entityColumn.setColumn(columnName); entityColumn.setJavaType(field.getJavaType()); if (field.getJavaType().isPrimitive()) { log.warn("通用 Mapper 警告信息: <[" + entityColumn + "]> 使用了基本类型,基本类型在动态 SQL 中由于存在默认值,因此任何时候都不等于 null,建议修改基本类型为对应的包装类型!"); } //OrderBy processOrderBy(entityTable, field, entityColumn); //处理主键策略 processKeyGenerator(entityTable, field, entityColumn); entityTable.getEntityClassColumns().add(entityColumn); if (entityColumn.isId()) { entityTable.getEntityClassPKColumns().add(entityColumn); } }
Example 20
Source File: SqlHelper.java From Mapper with MIT License | 4 votes |
/** * update set列 * * @param entityClass * @param entityName 实体映射名 * @param notNull 是否判断!=null * @param notEmpty 是否判断String类型!='' * @return */ public static String updateSetColumns(Class<?> entityClass, String entityName, boolean notNull, boolean notEmpty) { StringBuilder sql = new StringBuilder(); sql.append("<set>"); //获取全部列 Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass); //对乐观锁的支持 EntityColumn versionColumn = null; // 逻辑删除列 EntityColumn logicDeleteColumn = null; //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值 for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (versionColumn != null) { throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } versionColumn = column; } if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { if (logicDeleteColumn != null) { throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); } logicDeleteColumn = column; } if (!column.isId() && column.isUpdatable()) { if (column == versionColumn) { Version version = versionColumn.getEntityField().getAnnotation(Version.class); String versionClass = version.nextVersion().getCanonicalName(); sql.append("<bind name=\"").append(column.getProperty()).append("Version\" value=\""); //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append("@tk.mybatis.mapper.version.VersionUtil@nextVersion(") .append("@").append(versionClass).append("@class, "); if (StringUtil.isNotEmpty(entityName)) { sql.append(entityName).append("."); } sql.append(column.getProperty()).append(")\"/>"); sql.append(column.getColumn()).append(" = #{").append(column.getProperty()).append("Version},"); } else if (column == logicDeleteColumn) { sql.append(logicDeleteColumnEqualsValue(column, false)).append(","); } else if (notNull) { sql.append(SqlHelper.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty)); } else { sql.append(column.getColumnEqualsHolder(entityName) + ","); } } } sql.append("</set>"); return sql.toString(); }