【批量上下架商品】接口说明;
【批量上下架商品】接口文档;
批量上下架商品,在界面上的表现;可以看到,我们可以选择多个商品,来实现批量的上下架;
插:这儿的批处理操作:涉及到了【SpringMVC接收复合数据】、【Mybatis批处理】、【SQL语句拼凑】等以前介绍过的内容;
正式开发;
在ProductAdminController类中,创建批量上下架商品的方法:batchUpdateSellStatus()方法;/***后台批量上下架商品**@return*/@ApiOperation('批量上下架商品')@PostMapping('/admin/product/batchUpdateSellStatus')@ResponseBodypublicApiRestResponsebatchUpdateSellStatus(@RequestParam('ids')Integer[]ids,@RequestParam('sellStatus')IntegersellStatus){productServicbatchUpdateSellStatus(ids,sellStatus);returnApiRestResponssuccess();}说明:请求方式、url要符合接口文档的要求;因为前端传过来的ids这个参数,存在有多个值的情况:我们这儿使用数组来接收ids参数;关于SpringMVC接收复合参数,可以参考【SpringMVC入门与数据绑定SpringMVC数据绑定接收表单中的【复合数据】;】;只是,这儿我们使用的是数组去接收参数;Service层的处理批量上下架的逻辑方法,batchUpdateSellStatus()方法,在下一部分介绍;
在ProductServiceImpl实现类中,编写批量上下架的业务方法,batchUpdateSellStatus()方法;并在ProductServiceI接口中,反向生成该方法的声明;在ProductServiceImpl实现类中,编写批量上下架的业务方法,batchUpdateSellStatus()方法;/***批量上下架商品*@paramids*@paramsellStatus*/@OverridepublicvoidbatchUpdateSellStatus(Integer[]ids,IntegersellStatus){productMapper.batchUpdateSellStatus(ids,sellStatus);}没什么好说的,这儿调用了在Dao层编写的,实现批量更改商品status状态的方法:batchUpdateSellStatus()方法;这会在下一部分介绍;……………………………………………………在ProductServiceI接口中,反向生成该方法的声明;
在ProductMapper接口中定义批量更新商品状态的方法:batchUpdateSellStatus()方法;并在ProductMapper.xml中编写对应的实现SQL;在ProductMapper接口中定义批量更新商品状态的方法:batchUpdateSellStatus()方法;/***根据出入的【多个商品id】和【商品状态】,实现批量上下架功能;*@paramids*@paramsellStatus*@return*/intbatchUpdateSellStatus(@Param('ids')Integer[]ids,@Param('sellStatus')IntegersellStatus);说明:这儿就是接收Service传过来的两个参数;需要注意,如果有多个参数时候,是必须要使用@Param注解的;……………………………………………………在ProductMapper.xml中编写对应的实现SQL;
测试;
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点