tk.mybatis.mapper.code.Style Java Examples
The following examples show how to use
tk.mybatis.mapper.code.Style.
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: MyBatisMapperScannerConfig.java From Photo with GNU General Public License v3.0 | 6 votes |
@Bean(name="mapperHelper") public MapperScannerConfigurer mapperHelper(){ Properties properties = new Properties(); properties.setProperty("mappers",BaseMapper.class.getName()); properties.setProperty("IDENTITY","MYSQL"); // 数据库方言(主要用于:取回主键的方式) properties.setProperty("notEmpty","false"); // insert和update中,是否判断字符串类型!='',少数方法会用到 properties.setProperty("style", Style.camelhump.name()); MapperScannerConfigurer scan = new MapperScannerConfigurer(); scan.setSqlSessionFactoryBeanName("sqlSessionFactory"); // 多数据源时,必须配置 scan.setBasePackage("cc.gzvtc.*.dao");//mapper.java文件的路径 scan.setMarkerInterface(BaseMapper.class); // 直接继承了BaseDao接口的才会被扫描,basePackage可以配置的范围更大。 scan.setProperties(properties); return scan; }
Example #2
Source File: StringUtil.java From Mapper with MIT License | 6 votes |
/** * 根据指定的样式进行转换 * * @param str * @param style * @return */ public static String convertByStyle(String str, Style style) { switch (style) { case camelhump: return camelhumpToUnderline(str); case uppercase: return str.toUpperCase(); case lowercase: return str.toLowerCase(); case camelhumpAndLowercase: return camelhumpToUnderline(str).toLowerCase(); case camelhumpAndUppercase: return camelhumpToUnderline(str).toUpperCase(); case normal: default: return str; } }
Example #3
Source File: StringUtil.java From tk-mybatis with MIT License | 6 votes |
/** * 根据指定的样式进行转换 * * @param str * @param style * @return */ public static String convertByStyle(String str, Style style) { switch (style) { case camelhump: return camelhumpToUnderline(str); case uppercase: return str.toUpperCase(); case lowercase: return str.toLowerCase(); case camelhumpAndLowercase: return camelhumpToUnderline(str).toLowerCase(); case camelhumpAndUppercase: return camelhumpToUnderline(str).toUpperCase(); case normal: default: return str; } }
Example #4
Source File: ComplexEntityTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest() { config = new Config(); config.setStyle(Style.camelhump); configuration = new Configuration(); }
Example #5
Source File: NameStyleTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #6
Source File: IdTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #7
Source File: RegisterMapperTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #8
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #9
Source File: VersionTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #10
Source File: ColumnTypeTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #11
Source File: ColumnTest.java From Mapper with MIT License | 5 votes |
@Before public void beforeTest(){ config = new Config(); config.setStyle(Style.normal); configuration = new Configuration(); }
Example #12
Source File: TableTest.java From Mapper with MIT License | 4 votes |
@Before public void beforeTest() { config = new Config(); config.setStyle(Style.normal); }
Example #13
Source File: SqlHelperTest.java From Mapper with MIT License | 4 votes |
@Before public void beforeTest() { config = new Config(); config.setStyle(Style.normal); EntityHelper.initEntityNameMap(User.class, config); }
Example #14
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 #15
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 #16
Source File: Config.java From Mapper with MIT License | 4 votes |
public void setStyle(Style style) { this.style = style; }
Example #17
Source File: Config.java From Mapper with MIT License | 4 votes |
public Style getStyle() { return this.style == null ? Style.camelhump : this.style; }
Example #18
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testCamelhump() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhump)); } }
Example #19
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testCamelhumpLowercase() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndLowercase)); } }
Example #20
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testCamelhumpUppercase() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndUppercase)); } }
Example #21
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testLowercase() { for (String field : fields) { Assert.assertEquals(field.toLowerCase(), StringUtil.convertByStyle(field, Style.lowercase)); } }
Example #22
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testUppercase() { for (String field : fields) { Assert.assertEquals(field.toUpperCase(), StringUtil.convertByStyle(field, Style.uppercase)); } }
Example #23
Source File: StyleTest.java From Mapper with MIT License | 4 votes |
@Test public void testNormal() { for (String field : fields) { Assert.assertEquals(field, StringUtil.convertByStyle(field, Style.normal)); } }
Example #24
Source File: DataSourceAutoConfiguration.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
private void registryBean(String druidNodeName, MybatisNodeProperties nodeProperties, DruidProperties defaultProperties, Configuration configuration, BeanDefinitionRegistry registry) { if (nodeProperties == null) { return; } String mapperPackage = nodeProperties.getMapperPackage(); String typeAliasesPackage = nodeProperties.getTypeAliasesPackage(); String dbType = super.getDbType(nodeProperties.getMaster(), defaultProperties); Order order = nodeProperties.getOrder(); Dialect dialect = nodeProperties.getDialect(); Style style = nodeProperties.getStyle(); if (null == dialect) { dialect = Dialect.valoueOfName(dbType); } Mapper mappers = nodeProperties.getMapper(); if (mappers == null) { mappers = Mapper.valueOfDialect(dialect); } String basepackage = nodeProperties.getBasePackage(); if (StringUtils.isEmpty(basepackage)) { log.warn("BasePackage为空,db配置异常,当前配置数据源对象的名字{}", druidNodeName); basepackage = ""; } boolean primary = nodeProperties.isPrimary(); String dataSourceName = druidNodeName + "DataSource"; // String dataSourceMasterName = druidNodeName + "DataSource-Master"; String jdbcTemplateName = druidNodeName + "JdbcTemplate"; String transactionManagerName = druidNodeName; String sqlSessionFactoryBeanName = druidNodeName + "RegerSqlSessionFactoryBean"; String scannerConfigurerName = druidNodeName + "RegerScannerConfigurer"; AbstractBeanDefinition dataSource = super.createDataSource(nodeProperties, defaultProperties, dataSourceName); // AbstractBeanDefinition dataSourceMaster = // super.createDataSourceMaster(dataSourceName); AbstractBeanDefinition jdbcTemplate = super.createJdbcTemplate(dataSourceName); AbstractBeanDefinition transactionManager = super.createTransactionManager(dataSourceName); AbstractBeanDefinition sqlSessionFactoryBean = super.createSqlSessionFactoryBean(dataSourceName, mapperPackage, typeAliasesPackage, dialect, configuration); AbstractBeanDefinition scannerConfigurer = super.createScannerConfigurerBean(sqlSessionFactoryBeanName, basepackage, mappers, order, style,nodeProperties.getProperties()); dataSource.setLazyInit(true); dataSource.setPrimary(primary); dataSource.setScope(BeanDefinition.SCOPE_SINGLETON); // dataSourceMaster.setLazyInit(true); // dataSourceMaster.setScope(BeanDefinition.SCOPE_SINGLETON); jdbcTemplate.setLazyInit(true); jdbcTemplate.setPrimary(primary); jdbcTemplate.setScope(BeanDefinition.SCOPE_SINGLETON); transactionManager.setLazyInit(true); transactionManager.setPrimary(primary); transactionManager.setScope(BeanDefinition.SCOPE_SINGLETON); sqlSessionFactoryBean.setLazyInit(true); sqlSessionFactoryBean.setPrimary(primary); sqlSessionFactoryBean.setScope(BeanDefinition.SCOPE_SINGLETON); scannerConfigurer.setLazyInit(true); scannerConfigurer.setPrimary(primary); scannerConfigurer.setScope(BeanDefinition.SCOPE_SINGLETON); registry.registerBeanDefinition(dataSourceName, dataSource); // registry.registerBeanDefinition(dataSourceMasterName, // dataSourceMaster); registry.registerBeanDefinition(jdbcTemplateName, jdbcTemplate); registry.registerBeanDefinition(transactionManagerName, transactionManager); registry.registerBeanDefinition(sqlSessionFactoryBeanName, sqlSessionFactoryBean); registry.registerBeanDefinition(scannerConfigurerName, scannerConfigurer); if (primary) { registry.registerAlias(dataSourceName, "dataSource"); registry.registerAlias(jdbcTemplateName, "jdbcTemplate"); registry.registerAlias(transactionManagerName, "transactionManager"); } }
Example #25
Source File: MybatisNodeProperties.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
public void setStyle(Style style) { this.style = style; }
Example #26
Source File: MybatisNodeProperties.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
public Style getStyle() { return style; }
Example #27
Source File: StyleTest.java From tk-mybatis with MIT License | 4 votes |
@Test public void testCamelhumpLowercase() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndLowercase)); } }
Example #28
Source File: StyleTest.java From tk-mybatis with MIT License | 4 votes |
@Test public void testCamelhumpUppercase() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndUppercase)); } }
Example #29
Source File: StyleTest.java From tk-mybatis with MIT License | 4 votes |
@Test public void testCamelhump() { for (String field : fields) { System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhump)); } }
Example #30
Source File: StyleTest.java From tk-mybatis with MIT License | 4 votes |
@Test public void testLowercase() { for (String field : fields) { Assert.assertEquals(field.toLowerCase(), StringUtil.convertByStyle(field, Style.lowercase)); } }