public List selectAll() { return jdbcTemplate.queryForList("select * from user"); } @Override @DS("slave_1") public List selectByCondition() { return jdbcTemplate.queryForList("select * from user where age >10"); } }
Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@25be445f] was not registered for synchronization because synchronization is not active JDBC Connection [HikariProxyConnection@1330143761 wrapping com.mysql.cj.jdbc.ConnectionImpl@51e3d37e] will not be managed by Spring ==> Preparing: INSERT INTO goods ( name, num ) VALUES ( ?, ? ) ==> Parameters: 测试物品(String), 100(Long) <== Updates: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@25be445f] Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5c134052] was not registered for synchronization because synchronization is not active JDBC Connection [HikariProxyConnection@1112569408 wrapping com.mysql.cj.jdbc.ConnectionImpl@51e3d37e] will not be managed by Spring ==> Preparing: SELECT id,name,num,version FROM goods ==> Parameters: <== Columns: id, name, num, version <== Row: 11, 测试物品, 100, 1 <== Total: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5c134052] 2022-11-03 23:29:12.757 INFO 17156 --- [ main] c.a.learn.mybatisplus.DynamicDsTest : 物品:GoodsDO(id=11, name=测试物品, num=100, version=1) 2022-11-03 23:29:12.757 INFO 17156 --- [ main] c.a.learn.mybatisplus.DynamicDsTest : ================================= Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c232051] was not registered for synchronization because synchronization is not active JDBC Connection [HikariProxyConnection@366008009 wrapping com.mysql.cj.jdbc.ConnectionImpl@3ab35b9c] will not be managed by Spring ==> Preparing: INSERT INTO user ( name ) VALUES ( ? ) ==> Parameters: 测试人员(String) <== Updates: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c232051] Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4130a648] was not registered for synchronization because synchronization is not active JDBC Connection [HikariProxyConnection@1644128841 wrapping com.mysql.cj.jdbc.ConnectionImpl@3ab35b9c] will not be managed by Spring ==> Preparing: SELECT id,name FROM user ==> Parameters: <== Columns: id, name <== Row: 1, 测试人员 <== Total: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4130a648] 2022-11-03 23:29:12.769 INFO 17156 --- [ main] c.a.learn.mybatisplus.DynamicDsTest : 人员:UserDO(id=1, name=测试人员) 2022-11-03 23:29:12.785 INFO 17156 --- [ionShutdownHook] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource start closing .... 2022-11-03 23:29:12.785 INFO 17156 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : aacopy1 - Shutdown initiated... 2022-11-03 23:29:12.791 INFO 17156 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : aacopy1 - Shutdown completed. 2022-11-03 23:29:12.791 INFO 17156 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : aacopy - Shutdown initiated... 2022-11-03 23:29:12.792 INFO 17156 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : aacopy - Shutdown completed. 2022-11-03 23:29:12.792 INFO 17156 --- [ionShutdownHook] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource all closed success,bye