forked from castello/spring_basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestParamTest.java
More file actions
106 lines (91 loc) · 4.89 KB
/
RequestParamTest.java
File metadata and controls
106 lines (91 loc) · 4.89 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
98
99
100
101
102
103
104
105
106
package com.fastcampus.ch2;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class RequestParamTest {
@RequestMapping("/requestParam")
public String main(HttpServletRequest request) {
String year = request.getParameter("year");
// http://localhost/ch2/requestParam ---->> year=null
// http://localhost/ch2/requestParam?year= ---->> year=""
// http://localhost/ch2/requestParam?year ---->> year=""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam2")
// public String main2(@RequestParam(name="year", required=false) String year) { // 아래와 동일
public String main2(String year) {
// http://localhost/ch2/requestParam2 ---->> year=null
// http://localhost/ch2/requestParam2?year ---->> year=""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam3")
// public String main3(@RequestParam(name="year", required=true) String year) { // 아래와 동일
public String main3(@RequestParam String year) {
// http://localhost/ch2/requestParam3 ---->> year=null 400 Bad Request. required=true라서
// http://localhost/ch2/requestParam3?year ---->> year=""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam4")
public String main4(@RequestParam(required=false) String year) {
// http://localhost/ch2/requestParam4 ---->> year=null
// http://localhost/ch2/requestParam4?year ---->> year=""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam5")
public String main5(@RequestParam(required=false, defaultValue="1") String year) {
// http://localhost/ch2/requestParam5 ---->> year=1
// http://localhost/ch2/requestParam5?year ---->> year=1
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
// =======================================================================
@RequestMapping("/requestParam6")
public String main6(int year) {
// http://localhost/ch2/requestParam6 ---->> 500 java.lang.IllegalStateException: Optional int parameter 'year' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
// http://localhost/ch2/requestParam6?year ---->> 400 Bad Request, nested exception is java.lang.NumberFormatException: For input string: ""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam7")
public String main7(@RequestParam int year) {
// http://localhost/ch2/requestParam7 ---->> 400 Bad Request, Required int parameter 'year' is not present
// http://localhost/ch2/requestParam7?year ---->> 400 Bad Request, nested exception is java.lang.NumberFormatException: For input string: ""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam8")
public String main8(@RequestParam(required=false) int year) {
// http://localhost/ch2/requestParam8 ---->> 500 java.lang.IllegalStateException: Optional int parameter 'year' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
// http://localhost/ch2/requestParam8?year ---->> 400 Bad Request, nested exception is java.lang.NumberFormatException: For input string: ""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam9")
public String main9(@RequestParam(required=true) int year) {
// http://localhost/ch2/requestParam9 ---->> 400 Bad Request, Required int parameter 'year' is not present
// http://localhost/ch2/requestParam9?year ---->> 400 Bad Request, nested exception is java.lang.NumberFormatException: For input string: ""
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam10")
public String main10(@RequestParam(required=true, defaultValue="1") int year) {
// http://localhost/ch2/requestParam10 ---->> year=1
// http://localhost/ch2/requestParam10?year ---->> year=1
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
@RequestMapping("/requestParam11")
public String main11(@RequestParam(required=false, defaultValue="1") int year) {
// http://localhost/ch2/requestParam11 ---->> year=1
// http://localhost/ch2/requestParam11?year ---->> year=1
System.out.printf("[%s]year=[%s]%n", new Date(), year);
return "yoil";
}
} // class