IDEA 控制台打印Mybaits SQL语句

时间:2024-10-14 18:25:05
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.配置扫描mpper public class DBAutoConfig { //控制台输出sql语句 @PostConstruct public void init(){ org.apache.ibatis.logging.LogFactory.useLog4JLogging(); } //1.配置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.配置sqlSessionFactoryBean @Bean SqlSessionFactoryBean sqlSessionFactoryBean1(DataSource dataSource){ SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); return sqlSessionFactoryBean; } }