第198天学习打卡(谷粒商城 项目 排错)

排错

AttrServiceImpl.java下加入这个代码后 规格参数页面又不显示了

 @Override
     public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String type) {
 ​
 ​
         QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<>();
         if(catelogId!=0){
             queryWrapper.eq("catelog_id",catelogId);
        }
         String key = (String) params.get("key");
         if (!StringUtils.isEmpty(key)){
             queryWrapper.and((wrapper)->{
                 wrapper.eq("attr_id",key).or().like("attr_name",key);
            });
        }
         IPage<AttrEntity> page = this.page(
                 new Query<AttrEntity>().getPage(params),
                 queryWrapper
        );
         PageUtils pageUtils = new PageUtils(page);
         List<AttrEntity> records = page.getRecords();
         List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
             AttrRespVo attrRespVo = new AttrRespVo();
             BeanUtils.copyProperties(attrEntity, attrRespVo);//把attrEntity里面的属性拷贝到attrRespVo里面
             //1.设置分类和分组的名字
             //分组
             AttrAttrgroupRelationEntity attrId = relationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
 ​
             if (attrId != null) {
                 AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId());
                 attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
            }
             //分类
             CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
             if (categoryEntity != null) {
                 attrRespVo.setCatelogName(categoryEntity.getName());
            }
 ​
 ​
             return attrRespVo;
        }).collect(Collectors.toList());
         pageUtils.setList(respVos);
 ​
         return pageUtils;

 

第198天学习打卡(谷粒商城 项目 排错)

 

报错内容

 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
  at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
  at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
  at com.sun.proxy.$Proxy97.selectOne(Unknown Source)
  at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)
  at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:89)
  at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
  at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
  at com.sun.proxy.$Proxy98.selectOne(Unknown Source)
  at com.doudou.gulimall.product.service.impl.AttrServiceImpl.lambda$queryBaseAttrPage$1(AttrServiceImpl.java:109)
  at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
  at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
  at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
  at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
  at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
  at com.doudou.gulimall.product.service.impl.AttrServiceImpl.queryBaseAttrPage(AttrServiceImpl.java:123)

规格参数页面一直出错

B站学习网址:全网最强电商教程《谷粒商城》对标阿里P6/P7,40-60万年薪哔哩哔哩bilibili

 

上一篇:java中JDBC当中PreparedStatement和Statement的效率比较


下一篇:面试了198天,成功拿到阿里P7offer,全靠我啃烂这300套Java面试题