-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
97 lines (82 loc) · 2.99 KB
/
UserController.java
File metadata and controls
97 lines (82 loc) · 2.99 KB
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
package myspring.user.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import myspring.user.service.UserService;
import myspring.user.vo.UserVO;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/getUserList.do")
public String getUserLlist(Model model) {
List<UserVO> userList= userService.getUserList();
model.addAttribute("userList",userList); //역시 여기도 EL ${userList}로 충
return "userList"; //이제 beans-web.xml jsp확장자 지정
}
@RequestMapping("/getUser.do")
public ModelAndView getUser(@RequestParam String id) {
UserVO user= userService.getUser(id);
return new ModelAndView("userInfo", "user", user);
}
@RequestMapping("/insertUserForm.do")
public ModelAndView insertUserForm() {
List<String> genderList = new ArrayList<String>();
genderList.add("m");
genderList.add("f");
List<String> cityList = new ArrayList<String>();
cityList.add("seoul");
cityList.add("busan");
cityList.add("daegu");
Map<String, List<String>> map = new HashMap<>();
map.put("genderList", genderList);
map.put("cityList", cityList);
return new ModelAndView("userInsert","map",map);
}
@RequestMapping("/insertUser.do")
public String insertUser(@ModelAttribute UserVO user) {
if(user!=null)
userService.insertUser(user);
return "redirect:/getUserList.do";
}
@RequestMapping("/updateUserForm.do")
public ModelAndView updateUserForm(@RequestParam String id) {
UserVO user = userService.getUser(id);
List<String> genderList = new ArrayList<String>();
genderList.add("m");
genderList.add("f");
List<String> cityList = new ArrayList<String>();
cityList.add("seoul");
cityList.add("busan");
cityList.add("daegu");
Map<String, Object> map = new HashMap<String, Object>();
map.put("genderList", genderList);
map.put("cityList", cityList);
map.put("user", user);
return new ModelAndView("userUpdate", "map", map);
}
@RequestMapping("/updateUser.do")
public String updateUser(@ModelAttribute UserVO user) {
userService.updateUser(user);
return "redirect:/getUserList.do";
}
@RequestMapping("/deleteUser.do/{id}")
public String deleteUser(@PathVariable String id) {
userService.deleteUser(id);
return "redirect:/getUserList.do";
}
@ExceptionHandler
public String handleException(Exception e) {
return "viewError";
}
}