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

Class YoilTellerMVC

ch2/YoilTellerMVC.java:10–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected