<select id="findListBypage" parameterType="cn.wh.util.PageUtil" resultType="Role">
select * from t_role limit #{index},#{size}
</select>
/**
* 通过自定义类型来传参 实现分页功能 需要新建一个类型
*/
@Test
public void testPage1(){
PageUtil pu = new PageUtil();
pu.setIndex(3);
pu.setSize(3);
List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.findListBypage", pu);
for(Role r:list){
System.out.println(r.getName());
}
}
<select id="findListBypage" parameterType="map " resultType="Role">
select * from t_role limit #{index},#{size}
</select>
/**
* 可以通过map来传参 这样可以不用新建新的类型
*/
@Test
public void testPage2(){
Map<String,Integer> map = new HashMap<String,Integer>();
map.put("index", 0);
map.put("size", 3);
List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.findListBypage", map);
for(Role r:list){
System.out.println(r.getName());
}
}
<select id="findAll" resultType="Role">
select * from t_role
</select>
/**
* 使用rowBounds来实现分页
*/
@Test
public void testPage3(){
//第一个参数 是index,开始下标
//第二个参数 是size,每页显示记录数
RowBounds bounds = new RowBounds(3, 3);
List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.findAll", null,bounds);
for(Role r:list){
System.out.println(r.getName());
}
}
<select id="selectLike" parameterType="string" resultType="Role">
select *from t_role where name like #{name}
</select>
/**
* 模糊查询
*/
@Test
public void testLike1(){
List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.selectLike","%会员");
for(Role r:list){
System.out.println(r.getName());
}
}
<select id="selectLike1" parameterType="string" resultType="Role">
select *from t_role where name like concat(#{name},'%');
</select>
/**
* 模糊查询
*/
@Test
public void testLike2(){
List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.selectLike1","黄");
for(Role r:list){
System.out.println(r.getName());
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有