java分页缓存_mybatis-分页和缓存

本文介绍了在Java中使用MyBatis进行分页查询的方法,包括在DAO接口中配置分页参数,Mapper文件中的分页配置,以及测试分页查询的示例。此外,还提到了缓存的配置,但未给出具体细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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中配置分页

/p>

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

select * from t_student

select * from t_student

limit #{start},#{size}

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

select * from t_student where id=#{id}

select * from t_student where name like #{param1} and age=#{param2}

select * from t_student

where gradeId=#{gradeId}

and name like #{name}

and age=#{age}

select * from t_student

where gradeId=#{gradeId}

where name like #{name}

where age=#{age}

select * from t_student

gradeId=#{gradeId}

and name like #{name}

and age=#{age}

select * from t_student

gradeId=#{gradeId}

and name like #{name}

and age=#{age}

select * from t_student

gradeId in

#{gradeId}

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缓存的配置:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值