18、【 商品管理模块开发】——前台商品详情、列表、搜索、动态排序功能开发
2018-10-11 22:22
561 查看
版权声明:转载请注明出处~ https://blog.csdn.net/czjlghndcy/article/details/83019886
15、【 商品管理模块开发】——后台获取商品详情功能开发及PropertiesUtil配置工具,DateTimeUtil时间处理工具开发中有讲,不清楚可以到该片文章中查看。
在上面
#####2、前台查询商品列表接口
阅读更多
####1、接口编写:
在portal包下新建
ProductController类:
#####1、前台查询商品详情接口:
*Controller:
//前台查询商品详情接口 @RequestMapping("detail.do") @ResponseBody public ServerResponse<ProductDetailVo> detail(Integer productId){ return iProductService.getProductDetail(productId); }
*Service:
//前台商品详情查询 ServerResponse<ProductDetailVo> getProductDetail(Integer productId);
*ServiceImpl:
//前台商品详情查询 public ServerResponse<ProductDetailVo> getProductDetail(Integer productId){ if(productId == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc()); } Product product=productMapper.selectByPrimaryKey(productId); if(product==null){ return ServerResponse.createByErrorMessage("商品已下架或者删除"); } if(product.getStatus() != Const.ProductStatusEnum.ON_SALE.getCode()){ return ServerResponse.createByErrorMessage("商品已下架或者删除"); } ProductDetailVo productDetailVo=assembleProductDetailVo(product); return ServerResponse.createBySuccess(productDetailVo); }
其中
ProductDetailVo productDetailVo=assembleProductDetailVo(product);这一行代码在
15、【 商品管理模块开发】——后台获取商品详情功能开发及PropertiesUtil配置工具,DateTimeUtil时间处理工具开发中有讲,不清楚可以到该片文章中查看。
在上面
*ServiceImpl使用的
selectByPrimaryKey方法是使用逆向工程生成的,故不展示。
#####2、前台查询商品列表接口
*Controller:
//前台查询商品列表接口 @RequestMapping("list.do") @ResponseBody //商品详情列表分页 public ServerResponse<PageInfo> list(@RequestParam(value = "keyword",required = false) String keyword, @RequestParam(value = "categoryId",required = false)Integer categoryId, @RequestParam(value = "pageNum",defaultValue = "1")int pageNum, @RequestParam(value = "pageSize",defaultValue = "10") int pageSize, @RequestParam(value = "orderBy",defaultValue = "") String orderBy){ return iProductService.getProductByKeywordCategory(keyword,categoryId,pageNum,pageSize,orderBy); }
*Service:
//前台商品分页(根据关键字搜索) ServerResponse<PageInfo> getProductByKeywordCategory(String keyword,Integer categoryId,int pageNum,int pageSize,String orderBy);
*ServiceImpl:
//前台商品分页(根据关键字搜索) public ServerResponse<PageInfo> getProductByKeywordCategory(String keyword,Integer categoryId,int pageNum,int pageSize,String orderBy){ if(StringUtils.isBlank(keyword) && categoryId ==null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc()); } List<Integer> categoryIdList=new ArrayList<>(); if(categoryId !=null){ Category category=categoryMapper.selectByPrimaryKey(categoryId); if(category == null &&StringUtils.isBlank(keyword)){ //没有该分类,并且还没有关键字,这个时候返回一个空的集合,不能返回报错 PageHelper.startPage(pageNum,pageSize); List<ProductDetailVo> productDetailVoList =Lists.newArrayList(); PageInfo pageInfo =new PageInfo(productDetailVoList); return ServerResponse.createBySuccess(pageInfo); } categoryIdList = iCategoryService.selectCategoryAndChildrenById(category.getId()).getData(); } if(StringUtils.isNotBlank(keyword)){ keyword =new StringBuilder().append("%").append(keyword).append("%").toString(); } PageHelper.startPage(pageNum,pageSize); //排序处理 if(StringUtils.isNotBlank(orderBy)){ if(Const.ProductListOrderBy.PRICE_ASC_DESC.contains(orderBy)){ String[] orderByArray=orderBy.split("_"); PageHelper.orderBy(orderByArray[0]+" "+orderByArray[1]); } } List<Product> productList=productMapper.selectByNameAndCategoryIds(StringUtils.isBlank(keyword)?null:keyword,categoryIdList.size()==0?null:categoryIdList); List<ProductListVo> productListVoList=Lists.newArrayList(); for(Product product : productList){ ProductListVo productListVo=assembleProductListVo(product); productListVoList.add(productListVo); } //开始分页 PageInfo pageInfo=new PageInfo(productList); pageInfo.setList(productListVoList); return ServerResponse.createBySuccess(pageInfo); }
上面我们用到了我们自己定义的两个方法,下面将对应代码展示一下
selectCategoryAndChildrenById:
public ServerResponse<List<Integer>> selectCategoryAndChildrenById(Integer categoryId){ //调用递归算法 Set<Category> categorySet= Sets.newHashSet(); finChildCategory(categorySet,categoryId); List<Integer> categoryIdList= Lists.newArrayList(); if(categoryId !=null){ for(Category categoryItem : categorySet){ categoryIdList.add(categoryItem.getId()); } } return ServerResponse.createBySuccess(categoryIdList); }
selectByNameAndCategoryIds:
<!--根据商品名字和Id查询商品--> <select id="selectByNameAndCategoryIds" resultMap="BaseResultMap" parameterType="map"> select <include refid="Base_Column_List"/> from mmall_product where status=1 <if test="productName != null"> and name like #{productName} </if> <if test="categoryList != null"> and category_id in <foreach item="item" index="index" open="(" separator="," close=")" collection="categoryList"> #{item} </foreach> </if> </select>
####2、接口测试:
######1、前台商品查询:
######2、前台商品列表查询:
其中
orderBy=后面对应的是我们需要排序的方式。
阅读更多
相关文章推荐
- 22、【收货地址管理模块】——收货地址增、删、改、查、分页列表、地址详情的功能开发
- 【收货地址管理模块】——收货地址增、删、改、查、分页列表、地址详情的功能开发
- corethink功能模块探索开发(十)前台显示公告列表
- 电商平台搭建--商品管理功能模块开发(二)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- ASP.NET动态网站开发培训-25.论文管理系统(五、添加后台新增及修改功能)
- 电商平台搭建--分类管理功能模块开发
- Android 仿联系人列表 实现ListView的A-Z字母排序和过滤搜索功能,并挤压效果
- MVP框架做的登陆注册,商品列表,商品详情,购物车功能 RxJava+Retrofit ijkplayer EventBus ButterKnife
- QtQuick桌面应用程序开发指导 3)达到UI而功能_B 4)动态管理Note物_A
- jeesite快速开发平台(十)---内容管理模块 功能说明
- 1.读取excel文件,将输入存储到数据库中(JXL) 2.完成商品的检索相关功能 1.根据分类,显示分类下所有的商品信息,按照库存量从低到高排序(提供补货依据) 2.模糊搜索,根据商品信息(名
- 利用videoView创建播放器,实现展示视频列表和搜索sd卡功能 以及android6.0的动态授权等功能
- 设计一个学生成绩管理系统,实现对学生成绩的动态管理,实现对学生成绩的输入,显示,删除,查找,插入,最佳,保存,计算,排序等主要功能
- 框架 day81 涛涛商城项目-实现首页搜索功能,商品详情,描述,规格展示
- 免费使用Anole示例——动态创建带有排序功能和下拉列表风格的组合框
- Android 仿联系人列表 实现ListView的A-Z字母排序和过滤搜索功能