Annotation-based Controller
- @Controller
>> @Controller
>> public class TestClass { ... }
해당 클래스가 컨트롤러 클래스 임을 알려준다.
빈 설정 파일의 <context:component-scan base-package="packageName" /> 과 같은 태그를 작성하면 컨트롤러 클래스가 스프링에 자동 검색되게 해준다.
- @Resource
>> @Resource(name = "beanName")
name에 주어진 이름의 빈을 빈 설정에서 찾아 자동 주입 시켜준다.
- @RequestMapping
>> @RequestMapping(value = "/test/hello.do", method = RequestMethod.GET)
value에 주어진 URL 요청이 들어올 경우 해당 컨트롤러나 메서드가 실행된다.
method에 주어진 http 방식의 요청이 들어올 경우 실행된다.
- @ModelAttribute
>> public String test(@ModelAttribute("modelName") TestCommand command)
메서드 파라미터에 @ModelAttribute를 사용하고 폼 전송이 들어오면 input 태그 name 속성과 일치하는 command 클래스의 멤버 변수와 자동으로 매핑된다.
이 방법 외에도 다른 여러 사용법이 있다.
- @RequestParam
>> public String test(@RequestParam(value = "paramName", required = false) String arg, ...)
value에 주어진 이름과 같은 요청 파라미터와 자동적으로 매핑되며 required의 값에 따라 필수 파라미터 임을 나타낸다.
이 글은 스프링노트에서 작성되었습니다.