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
public List
public List
public List
public List
public List
public int updateStudent(Student student);
public int insertStudent(Student student);
public Student getStudentById(Integer id);
public List
public List
}
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
for(Student student:studentList){
System.out.println(student);
}
}
@Test
public void testFindStudent2(){
logger.info("查询学生");
Map
map.put("start", 3);
map.put("size", 3);
List
for(Student student:studentList){
System.out.println(student);
}
}
}
2.缓存
2.1缓存的配置: