mybatis-分页和缓存

1.分页

1.1在dao接口中配置分页参数:

package com.java1234.mappers;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;

import com.java1234.model.Student;


public interface StudentMapper {

public List searchStudents(Map map);

public List searchStudents2(Map map);

public List searchStudents3(Map map);

public List searchStudents4(Map map);

public List searchStudents5(Map map);

public List searchStudents6(String name,int age);

public int updateStudent(Student student);

public int insertStudent(Student student);

public Student getStudentById(Integer id);

public List findStudents(RowBounds rowBounds);

public List findStudents2(Map map);
}

1.2在ampper中配置分页


PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">















insert into t_student values(null,#{name},#{age},#{pic},#{remark});

















update t_student


name=#{name},


age=#{age},


where id=#{id}

1.3测试分页

package com.java1234.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.java1234.mappers.StudentMapper;
import com.java1234.model.Student;
import com.java1234.util.SqlSessionFactoryUtil;

public class StudentTest3 {

private static Logger logger=Logger.getLogger(StudentTest3.class);
private SqlSession sqlSession=null;
private StudentMapper studentMapper=null;

/**
* 测试方法前调用
* @throws Exception
*/
@Before
public void setUp() throws Exception {
sqlSession=SqlSessionFactoryUtil.openSession();
studentMapper=sqlSession.getMapper(StudentMapper.class);
}

/**
* 测试方法后调用
* @throws Exception
*/
@After
public void tearDown() throws Exception {
sqlSession.close();
}


@Test
public void testFindStudent(){
logger.info("查询学生");
int offset=0,limit=3;
RowBounds rowBounds=new RowBounds(offset,limit);
List studentList=studentMapper.findStudents(rowBounds);
for(Student student:studentList){
System.out.println(student);
}
}

@Test
public void testFindStudent2(){
logger.info("查询学生");
Map map=new HashMap();
map.put("start", 3);
map.put("size", 3);
List studentList=studentMapper.findStudents2(map);
for(Student student:studentList){
System.out.println(student);
}
}
}

 

2.缓存

2.1缓存的配置:


转载于:https://www.cnblogs.com/csy666/p/6536663.html

你可能感兴趣的:(mybatis-分页和缓存)