1、日志注解
@Slf4j
log.info("我是可爱的日志");
这个注解等于
private static final Logger log = LoggerFactory.getLogger(xxx.class);
需要 lombok插件 和 pom依赖
2、生成指定范围的随机数
org.apache.commons.lang3.RandomUtils int id = RandomUtils.nextInt(1, 11);
也可以生成long
3、日期解析成201801
new SimpleDateFormat("yyyyMM").format(new Date())
4、通过配置文件前缀解析成数据源
@ConfigurationProperties(prefix = "spring.datasource.test1")
spring.datasource.test1.driverClassName=com.mysql.jdbc.Driver
mapper扫描以及配置sqlsessionfactory 指定 xml
@MapperScan(basePackages = "com.redis.sentinel.mapper", sqlSessionTemplateRef = "test1SqlSessionTemplate") @Bean(name = "test1SqlSessionFactory") @Primary public SqlSessionFactory testSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return bean.getObject(); } @Bean(name = "test1SqlSessionTemplate") @Primary public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); }
具体参考sharing-jdbc 项目