1.新建SellerProductController 类
(先在productService中新增上下架方法,并且进行测试)
@Controller
@RequestMapping("/seller/product")
public class SellerProductController {
@Autowired
private ProductService productService;
/**
* 列表
*/
@GetMapping("/list")
public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size,
Map<String, Object> map) {
PageRequest request = new PageRequest(page - 1, size);
Page<ProductInfo> productInfoPage = productService.findAll(request);
map.put("productInfoPage", productInfoPage);
map.put("currentPage", page);
map.put("size", size);
return new ModelAndView("product/list", map);
}
/**
* 商品上架
*/
@RequestMapping("/on_sale")
public ModelAndView onSale(@RequestParam("productId") String productId,
Map<String, Object> map) {
try {
productService.onSale(productId);
} 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);
}
/**
* 商品下架
*/
@RequestMapping("/off_sale")
public ModelAndView offSale(@RequestParam("productId") String productId,
Map<String, Object> map) {
try {
productService.offSale(productId);
} 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);
}
}
2.将templates/common/list.ftl拷贝一份到templates/product/list.ftl,再将内容稍作更改