码迷,mamicode.com
首页 > 其他好文 > 详细

10月11 一些小的东西

时间:2018-10-11 21:56:54      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:tsql   row   lse   cat   exce   qualifier   class   ext   classname   

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 项目

10月11 一些小的东西

标签:tsql   row   lse   cat   exce   qualifier   class   ext   classname   

原文地址:https://www.cnblogs.com/lyon91/p/9774661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!