MCPcopy Create free account
hub / github.com/castello/spring_basic / YoilTellerMVC2

Class YoilTellerMVC2

ch2/YoilTellerMVC2.java:11–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import org.springframework.web.bind.annotation.RequestParam;
10
11@Controller
12public class YoilTellerMVC2 {
13 @ExceptionHandler(Exception.class)
14 public String catcher(Exception ex) {
15 return "yoilError";
16 }
17
18 @RequestMapping("/getYoilMVC2") // http://localhost/ch2/getYoilMVC2
19 public String main(@RequestParam(required=true) int year,
20 @RequestParam(required=true) int month,
21 @RequestParam(required=true) int day, Model model) {
22
23 // 1. 유효성 검사
24 if(!isValid(year, month, day))
25 return "yoilError"; // 유효하지 않으면, /WEB-INF/views/yoilError.jsp로 이동
26
27 // 2. 처리
28 char yoil = getYoil(year, month, day);
29
30 // 3. Model에 작업 결과 저장
31 model.addAttribute("year", year);
32 model.addAttribute("month", month);
33 model.addAttribute("day", day);
34 model.addAttribute("yoil", yoil);
35
36 // 4. 작업 결과를 보여줄 View의 이름을 반환
37 return "yoil"; // /WEB-INF/views/yoil.jsp
38 }
39
40 private char getYoil(int year, int month, int day) {
41 Calendar cal = Calendar.getInstance();
42 cal.set(year, month - 1, day);
43
44 int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
45 return " 일월화수목금토".charAt(dayOfWeek);
46 }
47
48 private boolean isValid(int year, int month, int day) {
49 if(year==-1 || month==-1 || day==-1)
50 return false;
51
52 return (1<=month && month<=12) && (1<=day && day<=31); // 간단히 체크
53 }
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected