zoukankan      html  css  js  c++  java
  • 10月11 一些小的东西

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

  • 相关阅读:
    C# 删除文件夹
    XML操作类
    C# winform 安装程序打包(自定义操作)
    复制Datatable结构和数据,并按条件进行筛选
    Sql_Case_When
    C# using 与Trycatchfinally的区别和用法
    Winform datagridview Excel 导入导出
    矩阵树定理学习笔记
    minmax容斥笔记及例题
    平衡树学习笔记
  • 原文地址:https://www.cnblogs.com/lyon91/p/9774661.html
Copyright © 2011-2022 走看看