【删除商品】接口简介;
【删除商品】接口文档;说明:至于为什么这个删除操作,请求方式是POST而不是DELETE;因为这是一个SpringMVC的简单请求;这个接口是需要管理员用户登录的,而我们在AdminFilterConfig中,也对其进行了统一的处理;
删除商品,在界面上的表现;
正式开发;
在ProductAdminController类中,创建删除商品的方法:deleteProduct()方法;/***后台删除商品*@paramid*@return*/@ApiOperation('删除商品')@PostMapping('/admin/product/delete')@ResponseBodypublicApiRestResponsedeleteProduct(@RequestParam('id')Integeri{productServicdelete(i;returnApiRestResponssuccess();}说明:请求方式,url要符合接口文档;因为前端的参数放在了url中,所以使用@RequestParam注解来帮助接收参数;然后调用service层的delete方法,去删除商品;这在下一部分会介绍;
在ProductServiceImpl实现类中,编写删除商品的方法delete();然后在ProductService接口中,反向生成方法的声明;在ProductServiceImpl实现类中,编写删除商品的方法delete();/***删除商品*@paramid*/@Overridepublicvoiddelete(Integeri{//先查查,看表里是否有这条数据ProductproductOld=productMapper.selectByPrimaryKey(i;//如果查不到数据,就抛出删除失败异常;if(productOld==nul{thrownewImoocMallException(ImoocMallExceptionEnuDELETE_ERROR);}//如果一切OK,就调用【mybatis-generator帮我们生成的】删除方法去删除;intcount=productMapper.deleteByPrimaryKey(i;//如果没有删除成功,就抛出删除失败异常;if(count==0){thrownewImoocMallException(ImoocMallExceptionEnuDELETE_ERROR);}}说明:删除前,先查看数据库中是否有这条数据;如果一切OK,就调用【mybatis-generator】插件帮我们生成的deleteByPrimaryKey()方法去删除;……………………………………………………然后在ProductService接口中,反向生成方法的声明;
测试【删除商品】接口;
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点