Mybatis-Plus配置日志
请先查看https://blog.csdn.net/weixin_43612925/article/details/120614456
1、编写配置文件.YML
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/mybatis
driver-class-name: com.mysql.jdbc.Driver
#配置日志
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2、启动测试类
@SpringBootTest
class MybatisPlusApplicationTests {
//继承了BaseMapper,所有的方法都来自父类
//我们也可以自定义自己的方法
@Autowired
mapper mapper;
@Test
void contextLoads() {
//参数是wrapper,条件构造器
//查询全部用户
List<user> list=mapper.selectList(null);
list.forEach(System.out::println);
}
}
3、测试结果
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@42383cb0] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1861616277 wrapping com.mysql.cj.jdbc.ConnectionImpl@3127cb44] will not be managed by Spring
==> Preparing: SELECT id,name,age,email FROM user
==> Parameters:
<== Columns: id, name, age, email
<== Row: 1, x, 11, wqtgwht@q
<== Row: 2, v, 22, dsrhdet@ef
<== Row: 3, a, 12, xdfb@qw
<== Row: 4, b, 13, cxbtrhsr@s
<== Row: 5, c, 14, dsh@qwe
<== Total: 5
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@42383cb0]
user(id=1, name=x, age=11, email=wqtgwht@q)
user(id=2, name=v, age=22, email=dsrhdet@ef)
user(id=3, name=a, age=12, email=xdfb@qw)
user(id=4, name=b, age=13, email=cxbtrhsr@s)
user(id=5, name=c, age=14, email=dsh@qwe)