这个方法要怎么用有谁知道
<V> List<V> listObjs(Wrapper<T> queryWrapper, Function<? super Object, V> mapper);
我要写一个方法,根据carVo的carNumber查询car_dept表,这个表里一个car_number会有多条数据,我需要的就是多条数据里的一个字段(dept_id)字段组合成的list,我写的方法如下:
public R update(@Valid @RequestBody CarVO carVO) {
List<Long> newDeptIds = carVO.getDeptIds();
LambdaQueryWrapper<CarDept> wrapper = Wrappers.<CarDept>query().lambda().eq(CarDept::getCarNumber, carVO.getCarNumber());
Function<CarDept, Long> function = new Function<CarDept, Long>() {
@Override
public Long apply(CarDept carDept) {
return carDept.getDeptId();
}
};
//这行代码报错 no instance(s) of type variable(s) exist so that Object conforms to CarDept
List<Long> newDeptIds = carDeptService.listObjs(wrapper , function);
return R.status(carService.updateById(carVO));
}
代码报错no instance(s) of type variable(s) exist so that Object conforms to CarDept
但是如果修改成下面这样就没有问题,谁能帮我找找原因吗
public R update(@Valid @RequestBody CarVO carVO) {
List<Long> newDeptIds = carVO.getDeptIds();
LambdaQueryWrapper<CarDept> wrapper = Wrappers.<CarDept>query().lambda().eq(CarDept::getCarNumber, carVO.getCarNumber());
List<CarDept> carDepts = carDeptService.list(wrapper);
//这行代码报错 no instance(s) of type variable(s) exist so that Object conforms to CarDept
List<Long> newDeptIds = carDeptService.listObjs(wrapper , function);
List<Long> oldDeptIds = carDepts.stream().map(carDept -> {
return carDept.getDeptId();
}).collect(Collectors.toList());
return R.status(carService.updateById(carVO));
}