|  |  | 
 |  |  | import jakarta.annotation.PostConstruct; | 
 |  |  | import org.apache.ibatis.session.SqlSessionFactory; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.context.annotation.Bean; | 
 |  |  | import org.springframework.context.annotation.Configuration; | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private List<SqlSessionFactory> sqlSessionFactoryList; | 
 |  |  |  | 
 |  |  |     @Value("${mybatis-plus.configuration.print-sql}") | 
 |  |  |     private boolean printSql; | 
 |  |  |     /** | 
 |  |  |      * 两个拦截器,自动生成ID,异常时输出SQL | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) { | 
 |  |  |             sqlSessionFactory.getConfiguration().addInterceptor(new AutoGenerateIdInterceptor()); | 
 |  |  |             sqlSessionFactory.getConfiguration().addInterceptor(new PrintExceptionSqlInterceptor()); | 
 |  |  |             if (printSql) { | 
 |  |  |                 sqlSessionFactory.getConfiguration().addInterceptor(new PrintSqlInterceptor()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  |