设置mybatis 是否打印日志

    @Bean(name = "dbzyqsV102SqlSessionFactory")
    // @Qualifier表示查找Spring容器中名字为blogDataSource的对象
    public SqlSessionFactory dbzyqsV102SqlSessionFactory(@Qualifier("dbzyqsV102DataSource") DataSource datasource)
            throws Exception {
        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
        mybatisSqlSessionFactoryBean.setDataSource(datasource);
        MybatisConfiguration configuration = new MybatisConfiguration();
        // 关闭驼峰
        configuration.setMapUnderscoreToCamelCase(false);
        configuration.addInterceptor(new PaginationInterceptor());
        if ("uat".equals(active)) {
            configuration.setLogImpl(org.apache.ibatis.logging.stdout.StdOutImpl.class);
        }
        mybatisSqlSessionFactoryBean.setConfiguration(configuration);
        Interceptor interceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.setProperty("helperDialect", "mysql");
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        properties.setProperty("supportMethodsArguments", "true");
        properties.setProperty("params", "pageNum=pageNumKey;pageSize=pageSizeKey;");
        interceptor.setProperties(properties);
        mybatisSqlSessionFactoryBean.setPlugins(new Interceptor[]{interceptor});
        mybatisSqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/dbzyqsV102/*.xml"));
        return mybatisSqlSessionFactoryBean.getObject();
    }

 

posted @ 2024-07-30 16:09  八英里  阅读(24)  评论(0编辑  收藏  举报