从零到企业级SSM电商项目实战教程(二十九)后台商品搜索功能开发

ProductManageController.java

@RequestMapping("search.do")
public ServerResponse productSearch(HttpSession session,String productName,Integer productId, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
    User user = (User)session.getAttribute(Const.CURRENT_USER);
    if(user == null){
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");

    }
    if(iUserService.checkAdminRole(user).isSuccess()){
        //填充业务
        return iProductService.searchProduct(productName,productId,pageNum,pageSize);
    }else{
        return ServerResponse.createByErrorMessage("无权限操作");
    }
}

IProductService.java

ServerResponse searchProduct(String productName,Integer productId,int pageNum,int pageSize);

ProductServiceImpl.java

public ServerResponse searchProduct(String productName,Integer productId,int pageNum,int pageSize){
    PageHelper.startPage(pageNum,pageSize);
    if(StringUtils.isNotBlank(productName)){
        productName = new StringBuilder().append("%").append(productName).append("%").toString();
    }
    List productList = productMapper.selectByNameAndProductId(productName,productId);
    List productListVoList = Lists.newArrayList();
    for(Product productItem : productList){
        ProductListVo productListVo = assembleProductListVo(productItem);
        productListVoList.add(productListVo);
    }
    PageInfo pageResult = new PageInfo(productList);
    pageResult.setList(productListVoList);
    return ServerResponse.createBySuccess(pageResult);
}

ProductMapper.java

List selectByNameAndProductId(@Param("productName")String productName,@Param("productId") Integer productId);

ProductMapper.xml


本站所有文章均来自互联网,如有侵权,请联系站长删除。极客文库 » 从零到企业级SSM电商项目实战教程(二十九)后台商品搜索功能开发
分享到:
赞(0)

评论抢沙发

评论前必须登录!