tk.mybatis.mapper.util.StringUtil Java Examples
The following examples show how to use
tk.mybatis.mapper.util.StringUtil.
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: HySwaggerMapperPlugin.java From jvue-admin with MIT License | 6 votes |
private void columnTypeAnnotation(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (this.columnTypeEnabled) { String columnType = "tk.mybatis.mapper.annotation.ColumnType"; String jdbcType = "org.apache.ibatis.type.JdbcType"; topLevelClass.addImportedType(columnType); topLevelClass.addImportedType(jdbcType); List<Field> fields = topLevelClass.getFields(); for (Field field : fields) { List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns(); for (IntrospectedColumn introspectedColumn : allColumns) if (field.getName().equals(introspectedColumn.getJavaProperty())) { String jdbcTypeName = introspectedColumn.getJdbcTypeName(); if(StringUtil.isEmpty(jdbcTypeName)){ continue; }else{ jdbcTypeName="JdbcType."+jdbcTypeName; } field.addAnnotation("@ColumnType(jdbcType=" + jdbcTypeName + ")"); } } } }
Example #2
Source File: GuestbookServiceImpl.java From ml-blog with MIT License | 6 votes |
@Override public void reply(Guestbook guestbook) throws GlobalException { guestbook.setNickname(commonMap.get("author").toString()); guestbook.setEmail(commonMap.get("email").toString()); guestbook.setStatus(0); guestbook.setDelStatus(0); guestbook.setType(2); this.guestbookMapper.insert(guestbook); // 发送邮件 Guestbook gb = this.guestbookMapper.selectByPrimaryKey(guestbook.getGuestbookId()); if (gb != null && !StringUtil.isEmpty(gb.getEmail())) { try { this.mailService.sendEmail(gb.getEmail(),guestbook.getNickname() + "的留言回复【"+commonMap.get("blogName").toString()+"】",guestbook.getContent()); } catch (Exception e) { e.printStackTrace(); } } }
Example #3
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 #4
Source File: Example.java From Mapper with MIT License | 6 votes |
private Example(Builder builder) { this.exists = builder.exists; this.notNull = builder.notNull; this.distinct = builder.distinct; this.entityClass = builder.entityClass; this.propertyMap = builder.propertyMap; this.selectColumns = builder.selectColumns; this.excludeColumns = builder.excludeColumns; this.oredCriteria = builder.exampleCriterias; this.forUpdate = builder.forUpdate; this.tableName = builder.tableName; if (!StringUtil.isEmpty(builder.orderByClause.toString())) { this.orderByClause = builder.orderByClause.toString(); } }
Example #5
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 #6
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 #7
Source File: AggregationProvider.java From Mapper with MIT License | 6 votes |
public static String aggregationSelectClause(Class<?> entityClass, String wrapKeyword, AggregateCondition condition) { Assert.notEmpty(condition.getAggregateProperty(), "aggregateProperty must have length; it must not be null or empty"); Assert.notNull(condition.getAggregateType(), "aggregateType is required; it must not be null"); EntityTable entityTable = EntityHelper.getEntityTable(entityClass); Map<String, EntityColumn> propertyMap = entityTable.getPropertyMap(); StringBuilder selectBuilder = new StringBuilder(); selectBuilder.append(condition.getAggregateType().name()); String columnName = propertyMap.get(condition.getAggregateProperty()).getColumn(); selectBuilder.append("(").append(columnName).append(")"); selectBuilder.append(" AS "); if (StringUtil.isNotEmpty(condition.getAggregateAliasName())) { selectBuilder.append(condition.getAggregateAliasName()); } else { selectBuilder.append(wrapKeyword(wrapKeyword, columnName)); } if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) { for (String property : condition.getGroupByProperties()) { selectBuilder.append(", "); columnName = propertyMap.get(property).getColumn(); selectBuilder.append(columnName).append(" AS ").append(wrapKeyword(wrapKeyword, columnName)); } } return selectBuilder.toString(); }
Example #8
Source File: SqlHelper.java From Mapper with MIT License | 6 votes |
/** * 判断自动==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(); }
Example #9
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 #10
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 #11
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 #12
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 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(); }
Example #13
Source File: CamelCaseTest.java From Mapper with MIT License | 5 votes |
@Test public void testCamelhumpToUnderline() { Assert.assertEquals("user_id", StringUtil.camelhumpToUnderline("userId")); Assert.assertEquals("sys_user", StringUtil.camelhumpToUnderline("sysUser")); Assert.assertEquals("sys_user_role", StringUtil.camelhumpToUnderline("sysUserRole")); Assert.assertEquals("s_function", StringUtil.camelhumpToUnderline("sFunction")); }
Example #14
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 #15
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 #16
Source File: DtreeServiceImpl.java From erp-framework with MIT License | 5 votes |
private List<Dtree> selectTreeMenuList(String roleId) { List<Dtree> origin = erpMenuMapper.getSysRoleTreeMenus(null); List<ErpMenu> menuList = erpMenuMapper.selectAll(); setBasicData(origin, menuList); if (!StringUtil.isEmpty(roleId)) { setCheckArrayStatus(roleId, origin); } if (origin != null && origin.size() > 0) { return getTargetList(origin); } return null; }
Example #17
Source File: Config.java From Mapper with MIT License | 5 votes |
/** * 获取序列格式化模板 * * @return */ public String getSeqFormat() { if (StringUtil.isNotEmpty(this.seqFormat)) { return this.seqFormat; } return "{0}.nextval"; }
Example #18
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 #19
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 #20
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 #21
Source File: SelectPropertyProvider.java From Mapper with MIT License | 5 votes |
/** * 判断是否需要拼接 where 条件 * @param value * @param notEmpty * @return */ public static boolean existsWhereCondition(Object value, boolean notEmpty) { boolean appendWhereCondition = true; if (Objects.isNull(value)) { log.warn("value is null! this will case no conditions after where keyword"); } else { if (String.class.equals(value.getClass()) && notEmpty && StringUtil.isEmpty(value.toString())) { // 如果 value 是 String 类型,则根据是否允许为空串做进一步校验来决定是否拼接 where 条件 appendWhereCondition = false; } } return appendWhereCondition; }
Example #22
Source File: UpdateByPrimaryKeySelectiveForceProvider.java From Mapper with MIT License | 5 votes |
/** * 判断自动!=null的条件结构 * * @param entityName * @param column * @param contents * @param empty * @return */ public String getIfNotNull(String entityName, EntityColumn column, String contents, boolean empty) { StringBuilder sql = new StringBuilder(); sql.append("<choose>"); sql.append("<when 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("</when>"); //指定的字段会被强制更新 sql.append("<when test=\""); sql.append(FORCE_UPDATE_PROPERTIES).append(" != null and ").append(FORCE_UPDATE_PROPERTIES).append(".contains('"); sql.append(column.getProperty()); sql.append("')\">"); sql.append(contents); sql.append("</when>"); sql.append("<otherwise></otherwise>"); sql.append("</choose>"); return sql.toString(); }
Example #23
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 #24
Source File: Example.java From Mapper with MIT License | 5 votes |
private String propertyforOderBy(String property) { if (StringUtil.isEmpty(property) || StringUtil.isEmpty(property.trim())) { throw new MapperException("接收的property为空!"); } property = property.trim(); if (!propertyMap.containsKey(property)) { throw new MapperException("当前实体类不包含名为" + property + "的属性!"); } return propertyMap.get(property).getColumn(); }
Example #25
Source File: MapperHelper.java From Mapper with MIT License | 5 votes |
/** * 配置属性 * * @param properties */ public void setProperties(Properties properties) { config.setProperties(properties); //注册解析器 if (properties != null) { String resolveClass = properties.getProperty("resolveClass"); if (StringUtil.isNotEmpty(resolveClass)) { try { EntityHelper.setResolve((EntityResolve) Class.forName(resolveClass).newInstance()); } catch (Exception e) { log.error("创建 " + resolveClass + " 实例失败!", e); throw new MapperException("创建 " + resolveClass + " 实例失败!", e); } } } //注册通用接口 if (properties != null) { String mapper = properties.getProperty("mappers"); if (StringUtil.isNotEmpty(mapper)) { String[] mappers = mapper.split(","); for (String mapperClass : mappers) { if (mapperClass.length() > 0) { registerMapper(mapperClass); } } } } }
Example #26
Source File: CamelCaseTest.java From tk-mybatis with MIT License | 5 votes |
@Test public void testCamelhumpToUnderline() { Assert.assertEquals("user_id", StringUtil.camelhumpToUnderline("userId")); Assert.assertEquals("sys_user", StringUtil.camelhumpToUnderline("sysUser")); Assert.assertEquals("sys_user_role", StringUtil.camelhumpToUnderline("sysUserRole")); Assert.assertEquals("s_function", StringUtil.camelhumpToUnderline("sFunction")); }
Example #27
Source File: MapperTemplate.java From tk-mybatis with MIT License | 5 votes |
/** * 获取实体类的表名 * * @param entityClass * @return */ protected String tableName(Class<?> entityClass) { EntityTable entityTable = EntityHelper.getEntityTable(entityClass); String prefix = entityTable.getPrefix(); if (StringUtil.isEmpty(prefix)) { //使用全局配置 prefix = mapperHelper.getConfig().getPrefix(); } if (StringUtil.isNotEmpty(prefix)) { return prefix + "." + entityTable.getName(); } return entityTable.getName(); }
Example #28
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 #29
Source File: Config.java From tk-mybatis 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 #30
Source File: Config.java From tk-mybatis with MIT License | 5 votes |
/** * 获取UUID生成规则 * * @return */ public String getUUID() { if (StringUtil.isNotEmpty(this.UUID)) { return this.UUID; } return "@java.util.UUID@randomUUID().toString().replace(\"-\", \"\")"; }