卖家类目
标签(空格分隔): springboot java wechat
商品修改
- controller层传参为非必传项(required=false)
/**
* 商品修改界面
* @param productId
* @param map
* @return
*/
@GetMapping("/index")
public ModelAndView index(@RequestParam(value = "productId",required = false)String productId,
Map map){
if(!StringUtils.isEmpty(productId)){
ProductInfo productInfo = productInfoService.findOne(productId);
map.put("productInfo",productInfo);
}
List categories = categoryService.findAll();
map.put("categories",categories);
return new ModelAndView("product/index",map);
}
- 前端显示和新增共用一个界面,其中每个值都没值则为空
担心各位看不懂这里贴整个页面
<#--头部文件-->
<#include "../common/header.ftl">
<#--边栏-->
<#include "../common/nav.ftl">
<#--内容-->
- 修改提交
表单验证
/**
* 商品修改表单
* @param form
* @param bindingResult
* @param map
* @return
*/
@PostMapping("/save")
public ModelAndView save(@Valid ProductForm form, BindingResult bindingResult,
Map map){
if(bindingResult.hasErrors()){
map.put("msg",bindingResult.getFieldError().getDefaultMessage());
map.put("url","/sell/seller/product/list");
return new ModelAndView("common/error",map);
}
try{
ProductInfo productInfo = productInfoService.findOne(form.getProductId());
BeanUtils.copyProperties(form,productInfo);
productInfoService.save(productInfo);
}catch (SellException e){
map.put("msg",e.getMessage());
map.put("url","/sell/seller/product/list");
return new ModelAndView("common/error",map);
}
map.put("url","/sell/seller/product/list");
return new ModelAndView("common/success",map);
}
- 商品新增 在之前的上面添加一个条件
/**
* 新增和修改判断
*/
if(!StringUtils.isEmpty(form.getProductId())){
productInfo = productInfoService.findOne(form.getProductId());
}else{
form.setProductId(KeyUtil.genUniqueKey());
}
商品类目开发
- 类目列表
@GetMapping("/list")
public ModelAndView list(Map map){
List categories = categoryService.findAll();
map.put("categoryList",categories);
return new ModelAndView("category/list",map);
}
- 类目修改
@GetMapping("/index")
public ModelAndView index(@RequestParam(value = "categoryId",required = false) Integer categpryId,Map map){
if(categpryId != null ){
ProductCategory category = categoryService.findOne(categpryId);
map.put("category",category);
}
return new ModelAndView("category/index",map);
}
- 类目修改和新增提交
/**
* 类目修改或者保存
* @param form
* @param bindingResult
* @param map
* @return
*/
@PostMapping("/save")
public ModelAndView save(@Valid CategoryForm form, BindingResult bindingResult, Map map){
if(bindingResult.hasErrors()){
map.put("msg",bindingResult.getFieldError().getDefaultMessage());
map.put("url","/sell/seller/category/list");
return new ModelAndView("common/error",map);
}
try {
//判断是否存在
ProductCategory productCategory = new ProductCategory();
if (form.getCategoryId() != null) {
productCategory = categoryService.findOne(form.getCategoryId());
}
BeanUtils.copyProperties(form, productCategory);
categoryService.save(productCategory);
map.put("url","/sell/seller/category/list");
return new ModelAndView("common/success",map);
}catch (SellException e){
map.put("msg",e.getMessage());
map.put("url","/sell/seller/category/list");
return new ModelAndView("common/error",map);
}
}
类目前端主界面和修改界面和商品列表一致
- 原视频UP主慕课网(SpringBoot企业级微信点餐项目)
- 本篇博客撰写人: XiaoJinZi 转载请注明出处
- 学生能力有限 附上邮箱: [email protected] 不足以及误处请大佬指责