首页>代码>基于SSM开发的网上订餐系统,包括前台页面和后台管理系统>/sourcecode/src/main/java/com/byh/biyesheji/controller/CategoryController.java
01 | package com.byh.biyesheji.controller; |
02 |
03 | import com.byh.biyesheji.pojo.Category; |
04 | import com.byh.biyesheji.service.CategoryService; |
05 | import org.springframework.beans.factory.annotation.Autowired; |
06 | import org.springframework.stereotype.Controller; |
07 | import org.springframework.ui.Model; |
08 | import org.springframework.web.bind.annotation.RequestMapping; |
09 | import org.springframework.web.bind.annotation.RequestParam; |
10 |
11 | import java.util.List; |
12 |
13 | /** |
14 | * 商品分类模块controller |
15 | */ |
16 | @Controller |
17 | @RequestMapping ( "/category" ) |
18 | public class CategoryController { |
19 |
20 | @Autowired |
21 | private CategoryService categoryService; |
22 |
23 | @RequestMapping ( "/list" ) |
24 | public String list(Model model){ |
25 | List<Category> list = categoryService.list(); |
26 | model.addAttribute( "list" ,list); |
27 | model.addAttribute( "size" ,list.size()); |
28 | return "productmodule/category-list" ; |
29 | } |
30 |
31 | @RequestMapping ( "/addCategory" ) |
32 | public String add( @RequestParam (value = "name" )String name){ |
33 | Category category = new Category(); |
34 | category.setName(name); |
35 | categoryService.save(category); |
36 | return "productmodule/category-list" ; |
37 | } |
38 |
39 | @RequestMapping ( "/delCategory" ) |
40 | public String del( @RequestParam (value = "id" ) int id){ |
41 | categoryService.del(id); |
42 | return "redirect:list" ; |
43 | } |
44 |
45 | @RequestMapping ( "/editCategory" ) |
46 | public String edit( @RequestParam (value = "id" ) int id,Model model){ |
47 | Category category = categoryService.get(id); |
48 | model.addAttribute( "category" ,category); |
49 | return "productmodule/category-edit" ; |
50 | } |
51 |
52 | @RequestMapping ( "/updateCategory" ) |
53 | public String update(Category category,Model model){ |
54 | categoryService.update(category); |
55 | return "redirect:list" ; |
56 | } |
57 | } |

微信网友_7298640909209600 LV2
2024年12月18日
120_wu LV4
2024年12月3日
charleswang LV7
2024年10月19日
柳咪华沙 LV7
2024年6月28日
rain112 LV31
2024年6月13日
qtingchh LV3
2024年5月3日
saaaaaa LV14
2024年4月16日
2131234536546 LV7
2024年3月31日
123ggf LV8
2024年3月15日
pangzhihui LV14
2024年3月5日

委屈99
3月2日
暂无贡献等级
哪里的完整版 LV8
3月1日
zyfile LV1
1月9日
ximM2025 LV1
1月8日
微信网友_7298640909209600 LV2
2024年12月18日
120_wu LV4
2024年12月3日
627384912
2024年12月3日
暂无贡献等级
yimaoermao LV1
2024年11月28日
DXming
2024年11月7日
暂无贡献等级
charleswang LV7
2024年10月19日