src/main/java/com/byh/biyesheji/controller/CategoryController.java
(完整代码) 1KBpackage com.byh.biyesheji.controller;
import com.byh.biyesheji.pojo.Category;
import com.byh.biyesheji.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* 商品分类模块controller
*/
@Controller
@RequestMapping("/category")
public class CategoryController {
@Autowired
private CategoryService categoryService;
@RequestMapping("/list")
public String list(Model model){
List<Category> list = categoryService.list();
model.addAttribute("list",list);
model.addAttribute("size",list.size());
return "productmodule/category-list";
}
@RequestMapping("/addCategory")
public String add(@RequestParam(value = "name")String name){
Category category = new Category();
category.setName(name);
categoryService.save(category);
return "productmodule/category-list";
}
@RequestMapping("/delCategory")
public String del(@RequestParam(value = "id")int id){
categoryService.del(id);
return "redirect:list";
}
@RequestMapping("/editCategory")
public String edit(@RequestParam(value = "id")int id,Model model){
Category category = categoryService.get(id);
model.addAttribute("category",category);
return "productmodule/category-edit";
}
@RequestMapping("/updateCategory")
public String update(Category category,Model model){
categoryService.update(category);
return "redirect:list";
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。