博客
关于我
谷粒商城day54-商品服务-API-平台属性-规格参数新增与VO与开发中各种O的含义
阅读量:763 次
发布时间:2019-03-23

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

项目开发经验分享

1. 模糊查询实现

AttrGroupServiceImpl中,我们实现了对属性组的查询功能,支持模糊查询。这通过数据库查询的动态条件构建,确保灵活性和效率。具体实现如下:

@Overridepublic PageUtils queryPage(Map
params, Long catalogId) { QueryWrapper
queryWrapper = new QueryWrapper<>(); if (catalogId != 0) { queryWrapper.eq("catalog_id", catalogId); } String key = (String) params.get("key"); if (StringUtils.isNotEmpty(key)) { queryWrapper.and(obj -> { obj.eq("attr_group_id", key).or().like("attr_group_name", key); }); } IPage
page = this.page( new Query
()().getPage(params), queryWrapper ); return new PageUtils(page);}

2. 规格参数新增问题

当新增规格参数时,发现属性分组的关联数据未同步更新,初步猜测为数据传输问题。经过排查发现,该实体类缺少关联字段attrGroupId,于是创建了新的VO类AttrVo来处理属性分组信息。

3. VO类设计原因

选择创建新的VO类而非直接修改实体类,是出于以下考虑:

1. 业务实体的封装

  • 简化数据传输交互
  • 保持核心实体的洁净性

2. 视图对象的作用

  • 接收与返回数据
  • 适配前后端需求

3.持久化对象的定义

  • 包含所有必要字段
  • 适用于数据库操作

4. service层修改

saveAttr方法中,我们使用AttrVo进行参数接收和业务处理:

@Overridepublic void saveAttr(AttrVo attrVo) {    AttrEntity attrEntity = new AttrEntity();    BeanUtils.copyProperties(attrVo, attrEntity);    this.save(attrEntity);    AttrAttrgroupRelationEntity relation = new AttrAttrgroupRelationEntity();    relation.setAttrGroupId(attrVo.getAttrGroupId());    relation.setAttrId(attrEntity.getAttrId());    attrAttrgroupRelationService.save(relation);}

通过以上方法,确保了数据传输过程的规范性和可维护性。希望这份经验分享能为您所用!

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

你可能感兴趣的文章
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>