mybatisplus
使用optional做数据拷贝
PhmDevice adds = Optional.ofNullable(bo).map(PhmDevice::new).orElse(null);
使用Spring的bean做拷贝
PhmDevice add = BeanUtil.copyProperties(bo, PhmDevice.class, "name", bo.getName()); //name为省略字段
1使用mybatisplus中遇到问题,主表找不到字段。
报错 can not find lambda cache for this property [pointId] of entity [com.weizu.baseInfo.domain.PhmThreshold]
要在实体表添加@TableField(exist = fasle,value = "point_id")
报错2,主表现在字段不存在使用注解@TableField(exist = false)表示该list不做映射关系
2.使用mybatisplus做一对多查询
//查询主表信息
LambdaQueryWrapper<PhmPoint> lqw = Wrappers.lambdaQuery(); lqw.eq(StringUtils.isNotBlank(bo.getPointNumber()), PhmPoint::getPointNumber, bo.getPointNumber()); lqw.eq(bo.getCreatedTime() != null, PhmPoint::getCreatedTime, bo.getCreatedTime()); Page<PhmPointVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
//查询子表数据 for (PhmPointVo e :result.getRecords()) //phmPointVo,phmPoint表中做@TableField(exist = fasle)
{ LambdaQueryWrapper<PhmThreshold> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
objectLambdaQueryWrapper.eq(StringUtils.isNotBlank(e.getPointId()), PhmThreshold::getPointId, e.getPointId()); //主表ID和从表pointID关联eq. PhmThreshold从表字段做映射关系@TableField(exist = fasle,value = "point_id")
List<PhmThreshold> collect = phmThresholdMapper.selectList(objectLambdaQueryWrapper); e.setPhmThresholds(collect);
e.setPhmThresholds(collect);
}
3,使用多表查询时候要在entity中的返回字段中加@TableField(exist=false),这样别的共用实体不会查询该字段,要不会报unknown column “xxx”.@TableField使用在多表中的

浙公网安备 33010602011771号