@RequestMapping("/test1")
@ResponseBody
public String test1(){
// 分页查询
Page page = new Page<>(1, 5);
// 升序排序
page.addOrder(OrderItem.asc("age"));
// age为20,根据name模糊查询
Page userIPage = mapper.selectPage(page, Wrappers.lambdaQuery().eq(User::getAge, 20).like(User::getName, "Jack"));
// 打印出查询结果
userIPage.getRecords().forEach(System.out::println);
return "success";
}
# 控制台
SELECT id, name, age, email FROM user WHERE (age = ? AND name LIKE ?) ORDER BY age ASC LIMIT ?
使用自定义的mySelectMap方法
List mySelectMap(Map param);
@RequestMapping("/test7")
@ResponseBody
public String test7(){
mapper.mySelectMap(Maps.newHashMap("name", "%a%")).forEach(System.out::println);
return "success";
}
# 控制台
select * from user WHERE name like ?
使用自定义的rowBoundList方法
List rowBoundList(RowBounds rowBounds, Map map);
@RequestMapping("/test11")
@ResponseBody
public String test11(){
RowBounds rowBounds = new RowBounds(0, 5);
List list = mapper.rowBoundList(rowBounds, Maps.newHashMap("name", "%"));
System.out.println("list.size=" + list.size());
return "success";
}
# 控制台
select * from user WHERE name like ?