IT노트(구)/Java
스프링 RequestMapping에서 파라미터 받아오는 예제(@RequestParam을 이용)
스프링연구소
2015. 12. 28. 06:49
스프링에서 Controller를 통해 RequestMapping을 할 때
파라미터는 다음과 같이 받아올 수 있다!(@RequestParam을 이용해서)
매개 변수에 어노테이션이 들어가는 형태인데
스프링이 얼마나 위대한(?) 프레임워크인지 다시 한 번 느낄 수 있다!
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class TestController {
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String home(Model model, @RequestParam String param1) {
System.out.println(param1); // param1로 던진 값을 받아올 수 있다.(/test?param1=abcd)
return "test";
}
}