我们在Mapper.xml文件中开启二级缓存时:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mam.mapper.UserMapper">
<!-- 在当前xml中使用二级缓存-->
<cache/>
<select id="queryUser" resultType="user">
select * from mybatis.user where id = #{id}
</select>
<update id="updateUser" parameterType="user">
update mybatis.user set name = #{name} ,pwd = #{pwd} where id =#{id} ;
</update>
</mapper>
在进行测试时:
@Test
public void test2(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.