web123456

IDEA Console Printing Mybaits SQL Statements

package com.study.mybatis.config; import org.apache.ibatis.logging.log4j.Log4jImpl; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.annotation.PostConstruct; import javax.sql.DataSource; @ComponentScan({""}) @Configuration @MapperScan("")//3. Configure scanning mpper public class DBAutoConfig { //console output sql statement @PostConstruct public void init(){ org.apache.ibatis.logging.LogFactory.useLog4JLogging(); } //1. Configure datesource @Bean public DataSource dataSource(){ DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(); driverManagerDataSource.setPassword("MySql!@#123"); driverManagerDataSource.setUsername("root"); driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false"); driverManagerDataSource.setDriverClassName(""); return driverManagerDataSource; } //2. Configure the sqlSessionFactoryBean. @Bean SqlSessionFactoryBean sqlSessionFactoryBean1(DataSource dataSource){ SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); return sqlSessionFactoryBean; } }