@RequestMapping("주소")요청 주소를 처리할 메서드를 매핑하는 어노테이션
GET/POST 가리지 않고 매핑 -> (속성을 통해서 지정 가능 or 다른 어노테이션 이용)
@RequestMapping(value="test", method = RequestMethod.GET)
@RequestMapping("test") // /test 요청 시 testMethod가 매핑하여 처리함
@GetMapping("주소")@PostMapping("주소")@PutMapping("주소")@DeleteMapping("주소")HttpServletRequest (Servlet 표준)자바 표준 서블릿 객체로 요청값 수동 추출
public String paramTest1(HttpServletRequest req) {
String inputName = req.getParameter("inputName");
}
Model (Spring 전용)@GetMapping("/example")
public String example(Model model) {
model.addAttribute("product", "커피잔");
model.addAttribute("price", 3000);
return "exampleView";
}@RequestParam()자동 형변환
@RequestParam("key") 자료형 매개변수명
속성
- value : 전달받은 input 태그의 name 속성값(파라미터 key)
- required : 입력된 name 속성값 파라미터 필수 여부 지정(기본값 true)
- required=true인 파라미터가 존재하지 않는다면 400(Bad Request) 에러
- defaultValue : 파라미터 중 일치하는 name속성값이 없을 경우에 대입할 값 지정
- required=false 인 경우 사용
// 단일 값
public String paramTest2(@RequestParam("title") String title)
// 속성 추가
@RequestParam(value="publisher", required = false,
defaultValue = "kh출판사") String publisher)
// 복수 값(배열, 리스트)
public String paramTest3(@RequestParam("color") String[] colorArr,
@RequestParam("fruit") List<String> fruitList)
// 모든 파라미터 key-value로 한번에
public String paramTest3(@RequestParam Map<String, Object> paramMap)
@ModelAttribute()public String paramTest4(@ModelAttribute MemberDTO inputMember){}
public String paramTest4(MemberDTO inputMember){}