1、是很么?
SimpleQuery可以对selectList查询后的结果使用Stream流进行操作,使其可以返回指定的结果,简洁了api的调用
2、怎么玩?
案例演示
(1) list操作
/**
* list(LambdaQueryWrapper<E> wrapper, SFunction<E, A> sFunction, Consumer<E>... peeks)
* 参数说明:
* param1 : 查询条件
* param2 : SFunction类型的函数式接口;你想要做了操作
*/
@Test
public void testList1() {
List<String> stringList = SimpleQuery.list(Wrappers.<Employee>lambdaQuery()
.gt(Employee::getId, 1), Employee::getName);
System.out.println("stringList = " + stringList);
}
/**
* list(LambdaQueryWrapper<E> wrapper, SFunction<E, A> sFunction, boolean isParallel, Consumer<E>... peeks)
* 参数说明:
* param1 : 查询条件
* param2 : SFunction类型的函数式接口;你想要做了操作
* param3 : 是否并行操作
* param4 : 转换后的后续流操作
*/
@Test
public void testList2() {
List<String> stringList = SimpleQuery.list(Wrappers.<Employee>lambdaQuery()
.gt(Employee::getId, 1), Employee::getName,
e -> Optional.of(e.getName()).map(String::toUpperCase).ifPresent(e::setName));
System.out.println("stringList = " + stringList);
}
(2) map操作
@Test
public void testMap1(){
Map<Integer, Employee> keyedMap = SimpleQuery.keyMap(Wrappers.<Employee>lambdaQuery()
.gt(Employee::getId, 1), Employee::getId);
System.out.println("keyedMap = " + keyedMap);
}
@Test
public void testMap2(){
Map<Integer, Employee> keyed = SimpleQuery.keyMap(Wrappers.<Employee>lambdaQuery()
.gt(Employee::getId, 1), Employee::getId, Employee::getName);
System.out.println("keyed = " + keyed);
(3) group操作
@Test
public void testGroup(){
Map<String, List<Employee>> map = SimpleQuery.group(Wrappers.<Employee>lambdaQuery()
.gt(Employee::getId, 1), Employee::getSex);
System.out.println("map = " + map);
}
标签:map,MybatisPlus,SimpleQuery,System,getId,特性,Employee,stringList
From: https://www.cnblogs.com/qbbit/p/17365365.html