Mybatis的日志工厂<setting name=“logImpl“ value=““/>

 

日志可以帮我们把重要的信息输出出来,这样出错的时候,可以借助日志可以查看哪里有问题

比如下面这个问题,我先查出状态为0的数据,却一直查出来的是全部的数据

如果没有日志,又不报错,类似这样的问题,如果不知道哪里 出错,要找出问题那简直就是费时费力,所以还是要把sql日志输出出来,这样就能知道问题在哪里了

Mybatis的日志工厂我们先看官方文档Mybatis官网

在mybatis的核心配置文件,添加日志配置

<setting name="logImpl" value="STDOUT_LOGGING"/>

STDOUT_LOGGING是标准日志。mybatis自带的

再次运行单元测试就可以看到日志输出了

至于我们上面遇到的问题,这里也说明了

Mybatis动态传参数值为0时,条件无效的问题

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 缩小扫描范围到 com.itheima.SpringMVC --> <context:component-scan base-package="com.itheima.SpringMVC"/> <bean id="User" class="com.itheima.SpringMVC.pojo.User"> <property name="username" value="涂大钧"></property> <property name="password" value="123"></property> </bean> <!--数据源--> <context:property-placeholder location="classpath*:jdbc.properties"/> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!--配置sql--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!--别名扫包--> <property name="typeAliasesPackage" value="com.itheima.SpringMVC.pojo"></property> <!--指定XML文件位置--> <!--mybatis-config.xml--> <property name="configLocation" value="classpath:/mybatis-mvc-config.xml" /> </bean> <!--指定Mapper XML文件位置--> <!--扫描Mapper--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> <property name="basePackage" value="com.itheima.SpringMVC.Mapper"></property> </bean> <!-- 事务管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--开启注解驱动的事务管理--> <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> </beans><?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 引入外部配置文件 --> <properties resource="jdbc.properties"> <!-- 可以在这里添加默认属性值 --> </properties> <!-- 设置 MyBatis 核心配置 --> <settings> <!-- 开启驼峰命名自动映射,如将数据库字段 user_name 映射到 Java 属性 userName --> <setting name="mapUnderscoreToCamelCase" value="true"/> <!-- 开启二级缓存 --> <setting name="cacheEnabled" value="true"/> <!-- 开启延迟加载 --> <setting name="lazyLoadingEnabled" value="true"/> <!-- 开启 aggressiveLazyLoading 会导致所有关联对象在被访问时立即加载 --> <setting name="aggressiveLazyLoading" value="true"/> <!-- 配置日志实现 --> <setting name="logImpl" value="STDOUT_LOGGING"/> </settings> <!-- 配置类型别名,简化映射 --> <typeAliases> <package name="com.itheima.SpringMVC.pojo"/> </typeAliases> <!-- 配置插件 --> <plugins> <!-- PageHelper 分页插件 --> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <!-- 可选配置 --> <property name="reasonable" value="true"/> <property name="supportMethodsArguments" value="true"/> <property name="params" value="count=countSql"/> </plugin> </plugins> <!-- 配置数据库环境 --> <environments default="development"> <environment id="development"> <!-- 使用 JDBC 事务管理器 --> <transactionManager type="JDBC"/> <!-- 配置数据源,使用 POOLED 连接池 --> <dataSource type="POOLED"> <property name="driver" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- 可选配置:连接池参数 --> <property name="poolMaximumActiveConnections" value="10"/> <property name="poolMaximumIdleConnections" value="5"/> </dataSource> </environment> </environments> <!-- 注册映射器 --> <mappers> <package name="com.itheima.SpringMVC.Mapper" /> <!-- <mapper resource="SpringMVC/Mapper/UsersMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/UserMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/IdCardMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/GoodsMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/GoodsTypeMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/OrdersMapper.xml"/>--> <!-- <mapper resource="SpringMVC/Mapper/OrderItemsMapper.xml"/>--> </mappers> </configuration>有问题吗
05-30
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

深知她是一场梦

你打不打赏,我都会一直写博客

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值