-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFoodInfoController.java
101 lines (88 loc) · 3.75 KB
/
FoodInfoController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.food.foodweb.controller;
import com.food.foodweb.model.Comment;
import com.food.foodweb.model.Food;
import com.food.foodweb.model.OrderedFood;
import com.food.foodweb.service.FoodInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
public class FoodInfoController {
public FoodInfoService foodinfoService;
@Autowired
public void setFoodInfoService(FoodInfoService foodinfoService) {
this.foodinfoService = foodinfoService;
}
@GetMapping("/findinfo")
public String findFoodinfoByName(String name, Model model) {
Food food = foodinfoService.findFoodByName(name);
model.addAttribute("food", food);
return "make";
}
@GetMapping("/Collect")
public String insertFoodByName(String userName, String foodName, String date, Model model, HttpSession session) {
OrderedFood orderedFood = foodinfoService.findCollectInfoByFoodName(foodName);
if (orderedFood != null) {
model.addAttribute("msg", "This food has been collected!");
} else {
boolean ret = foodinfoService.insertFoodByName(userName, foodName, date);
if (ret) {
model.addAttribute("msg", "Successfully collected!");
} else {
model.addAttribute("msg", "Collection failed!");
}
}
Food food = foodinfoService.findFoodByName(foodName);
session.setAttribute("food", food);
return "make";
}
@GetMapping("/CollectInfo")
public String findCollectInfoByName(String name, Model model) {
List<OrderedFood> orderedFoods = foodinfoService.findCollectInfoByName(name);
model.addAttribute("orderedFoods", orderedFoods);
return "collect";
}
@GetMapping("/collectDel")
public String del(String food_name, String user_name, Model model) {
boolean ret = foodinfoService.delCollect(food_name, user_name);
List<OrderedFood> orderedFoods = foodinfoService.findCollectInfoByName(user_name);
model.addAttribute("orderedFoods", orderedFoods);
return "collect";
}
@GetMapping("/Comment")
public String Comment(String name,Model model) {
List<Comment> comments=foodinfoService.findAllComments();
model.addAttribute("comments",comments);
return "comment";
}
@GetMapping("/insertComment")
public String insertComment(String name,String comment,String date,Model model) {
boolean ret=foodinfoService.insertComment(name,comment,date);
List<Comment> comments=foodinfoService.findAllComments();
model.addAttribute("comments",comments);
return "comment";
}
@GetMapping("/foodculture")
public String findAll(Model model, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "8") int pageSize)
{
PageInfo<Food> cultureInfo = foodinfoService.findAllinfo(pageNum, pageSize);
model.addAttribute("cultureInfo", cultureInfo);
return "foodculture";
}
@GetMapping("/CommentManageSy")
public String CommentManageSy(Model model) {
List<Comment> comments=foodinfoService.findAllComments();
model.addAttribute("comments",comments);
return "commentmanagesy";
}
@GetMapping("/commentDel")
public String CommentManageSy(String comment) {
boolean ret=foodinfoService.commentDel(comment);
return "redirect:CommentManageSy";
}
}