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使用在多表中的

posted @   党王  阅读(194)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示