博客
关于我
谷粒商城day55-商品服务-API-平台属性-规格参数列表
阅读量:761 次
发布时间:2019-03-23

本文共 2127 字,大约阅读时间需要 7 分钟。

需求分析与查询功能实现

打开规格参数界面时,与进入界面后点击某分类时,均会发出两个まったく相同的HTTP请汤汚,但两次请汤汚的参数略有不同。这两个请求基于不同的条件执行,刚进入界面时的点击则基于分类的ID值完成查询。

截图1

截图2

查询功能实现

为完成查询功能,我们设计并实现了 AttrResponseVo 类,该类继承自 AttrEntity 类,主要补充了 catelogName 和 groupName 两个属性。这些属性与原始的 PO 类相比,额外提供了分类名称和组别名称等信息。

在 service 层实现中,我们根据不同的 catelogId 值构造条件查询。具体来说:

  • 如果 catelogId 不为0,则添加 catelog_id 进行等值查询
  • 如果提供了 searchKey 关键词,则在 attr_id 和 attr_name 字段上执行精确查询或模糊查询
  • 通过以上逻辑,我们获取到对应的记录列表,并将结果转换为 AttrResponseVo 类格式返回。与此同时,为了确保分类信息的完整性,我们 调用了后台服务 拿到对应的分类名称信息和组别名称信息,将其动态注入 AttrResponseVo 对象中。

    代码实现如下:

    @Overridepublic PageUtils baseAttrList(Map
    params, Long catelogId) { QueryWrapper
    queryWrapper = new QueryWrapper<>(); if (catelogId != 0) { queryWrapper.eq("catelog_id", catelogId); } String searchKey = (String) params.get("searchKey"); if (StringUtils.isNotEmpty(searchKey)) { queryWrapper.and(obj -> { obj.eq("attr_id", searchKey).or().like("attr_name", searchKey); }); } IPage
    page = this.page( new Query
    () .getPage(params), queryWrapper ); PageUtils pageUtils = new PageUtils(page); List
    attrResponseVos = page.getRecords().stream() .map(attrEntity -> { AttrResponseVo attrResponseVo = new AttrResponseVo(); BeanUtils.copyProperties(attrEntity, attrResponseVo); CategoryEntity categoryEntity = categoryService.getById( attrEntity.getCatelogId() ); if (categoryEntity != null) { attrResponseVo.setCatelogName(categoryEntity.getName()); } AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationService.getOne( new QueryWrapper
    () .eq("attr_id", attrEntity.getAttrId()) ); if (attrAttrgroupRelationEntity != null) { AttrGroupEntity attrGroupEntity = attrGroupService.getById( attrAttrgroupRelationEntity.getAttrGroupId() ); attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName()); } return attrResponseVo; }) .collect(Collectors.toList()); pageUtils.setList(attrResponseVos); return pageUtils;}

    截图3

    截图4

    转载地址:http://pfezk.baihongyu.com/

    你可能感兴趣的文章
    MTK Android 如何获取系统权限
    查看>>
    MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
    查看>>
    MySQL - ERROR 1406
    查看>>
    mysql - 视图
    查看>>
    MySQL - 解读MySQL事务与锁机制
    查看>>
    MTTR、MTBF、MTTF的大白话理解
    查看>>
    mt_rand
    查看>>
    mysql -存储过程
    查看>>
    mysql /*! 50100 ... */ 条件编译
    查看>>
    mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
    查看>>
    mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
    查看>>
    mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
    查看>>
    mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
    查看>>
    MySQL 8.0 恢复孤立文件每表ibd文件
    查看>>
    MySQL 8.0开始Group by不再排序
    查看>>
    mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
    查看>>
    multi swiper bug solution
    查看>>
    MySQL Binlog 日志监听与 Spring 集成实战
    查看>>
    MySQL binlog三种模式
    查看>>
    multi-angle cosine and sines
    查看>>