第二十一章第三节:规格参数删除(批量)功能
规格参数删除请求:/product/attr/delete
请求参数:
attrIds:[5, 6]
响应数据示例:
{
"msg": "success",
"code": 0
}
操作数据库表:
pms_attr(基本属性)
pms_attr_attrgroup_relation(规格参数和属性分组的关联关系)
1、定义规程参数删除接口
com.applesnt.onlinemall.product.service.AttrService
void deleteByIds(List<Long> asList);
2、定义规程参数删除接口实现
com.applesnt.onlinemall.product.service.impl.AttrServiceImpl
/*注入关联关系dao*/
@Autowired
AttrAttrgroupRelationDao relationDao;
@Transactional
@Override
public void deleteByIds(List<Long> asList) {
for (Long attrId : asList) {
/*根据attrid删除规格参数数据*/
this.baseMapper.deleteById(attrId);
/*定义一个查询对象*/
QueryWrapper<AttrAttrgroupRelationEntity> wrapper = new QueryWrapper<AttrAttrgroupRelationEntity>();
wrapper.eq("attr_id",attrId);
/*根据attrId查询关联表,如果有记录就做删除操作*/
int count = relationDao.selectCount(wrapper);
if(count>0){
this.relationDao.delete(wrapper);
}
}
}
3、controller调用
com.applesnt.onlinemall.product.controller.AttrController
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] attrIds){
attrService.deleteByIds(Arrays.asList(attrIds));
return R.ok();
}

浙公网安备 33010602011771号