mybatis-mybatis二级缓存的配置

SqlMapConfig.xml的配置:(默认为true)

mybatis-mybatis二级缓存的配置_第1张图片

	
		
		
		
		
		
		
	


mapper.xml的配置:


返回的pojo类要实现序列化接口:



二级缓存测试:

package com.itcast.mybatis.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.itcast.mybatis.mapper.new_po_mapper;
import com.itcast.mybatis.newpo.new_po;
import com.itcast.mybatis.po.orderdetail;
import com.itcast.mybatis.po.orders;
import com.itcast.mybatis.po.users;

public class Test {
	public static void main(String []args) throws IOException{
		InputStream inputStream=Resources.getResourceAsStream("SqlMapConfig.xml");
		SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream); 
		SqlSession sqlSession=sqlSessionFactory.openSession();
		new_po_mapper New_po_mapper=sqlSession.getMapper(new_po_mapper.class);
		users user=New_po_mapper.findUserById(1);
		System.out.println(user.getUsername());
		sqlSession.close();
		
		SqlSession sqlSession1=sqlSessionFactory.openSession();
		new_po_mapper New_po_mapper1=sqlSession1.getMapper(new_po_mapper.class);
		users user1=New_po_mapper1.findUserById(1);
		System.out.println(user1.getUsername());
		sqlSession.close();
	}
}


你可能感兴趣的:(mybatis)