mybatis-plus listObjs的使用|lambda function错误

这个方法要怎么用有谁知道

<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));
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值