第一种方法使用索引
一般不使用,不记录
第二种方法使用注解
接口
List<Shop> getShopListByPageAno(@Param(value = "offset") int offset, @Param(value = "pagesize") int pagesize); |
mapper
<select id="getShopListByPageAno" resultMap="simpleResultMap" > select * from tb_shop ORDER BY CONVERT(shop_name USING gbk) limit #{offset}, #{pagesize}</select> |
用例
@Testpublic void testGetShopListByPageAno() { String template = "查询结果: %s"; SqlSession session = MyBatisUtil.getSqlSession(); ShopMapper mapper = session.getMapper(ShopMapper.class); System.out.printf(template, mapper.getShopListByPageAno(2, 1)); session.close();} |
第三种方法, 通过Map来传递
接口
List<Shop> getShopListByPageMap(Map<String, Object> map); |
mapper
<select id="getShopListByPageMap" resultMap="simpleResultMap" > select * from tb_shop ORDER BY CONVERT(shop_name USING gbk) limit #{offset}, #{pagesize}</select> |
用例
@Testpublic void testGetShopListByPage() { String template = "查询结果: %s"; SqlSession session = MyBatisUtil.getSqlSession(); ShopMapper mapper = session.getMapper(ShopMapper.class); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("offset", 2); paramMap.put("pagesize", 2); System.out.printf(template, mapper.getShopListByPageMap(paramMap)); session.close();} |
原文地址:https://www.cnblogs.com/litran/p/10543835.html
时间: 2024-10-30 08:18:39