> 文章列表 > 电商项目8:平台属性

电商项目8:平台属性

电商项目8:平台属性

电商项目8:平台属性

  • 1、后端
    • 1.1、属性分组模糊查询
    • 1.2、商品属性新增功能:保存关联关系

1、后端

1.1、属性分组模糊查询

需要改造。当前端传0时候。模糊查询功能有点问题

AttrGroupServiceImpl

 @Overridepublic PageUtils queryPage(Map<String, Object> params, Long catelogId) {QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>();// 当前端传了keyString key = (String)params.get("key");if (!StringUtils.isEmpty(key)){// select * from pms_attr_group where catelog_id = ? and (attr_gruop_id = ? or attr_group_name like %%)wrapper.and((obj)->{obj.eq("attr_group_id",key).or().like("attr_group_name",key);});}// 当前端的catelogId为0,没传的时候,查询所有if (catelogId == 0){return new PageUtils(this.page(new Query<AttrGroupEntity>().getPage(params),wrapper));}// 当前端cateLogId不为0,则wrapper.eq("catelog_id",catelogId);IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),wrapper);return new PageUtils(page);}

1.2、商品属性新增功能:保存关联关系

电商项目8:平台属性

电商项目8:平台属性
没有插入关联关系,需重写方法

1、创建vo文件夹。
接收页面传递来的数据,封装对象
将业务处理完成的对象,封装成页面要用的数据

AttrVo

package com.ljs.gulimall.product.vo;import lombok.Data;@Data
public class AttrVo {private Long attrId;/* 属性名*/private String attrName;/* 是否需要检索[0-不需要,1-需要]*/private Integer searchType;/* 值类型[0-为单个值,1-可以选择多个值]*/private Integer valueType;/* 属性图标*/private String icon;/* 可选值列表[用逗号分隔]*/private String valueSelect;/* 属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性]*/private Integer attrType;/* 启用状态[0 - 禁用,1 - 启用]*/private Long enable;/* 所属分类*/private Long catelogId;/* 快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整*/private Integer showDesc;/* 属性分组id*/private Long attrGroupId;
}

AttrController

 /* 保存*/@RequestMapping("/save")// @RequiresPermissions("product:attr:save")public R save(@RequestBody AttrVo attr){attrService.saveDetail(attr);return R.ok();}

AttrService

void saveDetail(AttrVo attr);

AttrServiceImpl

##@Transactional生效的前提是

@EnableTransactionManagement注解在配置类上。并且扫描到指定的dao层

@Transactional一般用于一次多个写操作

    @Transactional@Overridepublic void saveDetail(AttrVo attr) {// 1、保存分组信息AttrEntity attrEntity = new AttrEntity();BeanUtils.copyProperties(attr,attrEntity);this.save(attrEntity);// 2、保存关联关系AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();relationEntity.setAttrGroupId(attr.getAttrGroupId());relationEntity.setAttrId(attrEntity.getAttrId());relationService.save(relationEntity);}

电商项目8:平台属性
电商项目8:平台属性

电商项目8:平台属性