ModelAttribute
-
Spring Boot - @PathVariable & @RequestParam & @ModelAttributeFramework & Library/Spring Boot 2023. 2. 6. 13:27
@PathVariable & @RequestParm & @ModelAttribute @PathVariable http://localhost:8080/api/member/17 http://localhost:8080/api/member/25 REST API에서 위와 같이 URI에 변수가 들어가는 것을 본 적 있을 것이다. 위 URI에서 밑줄 친 부분이 @PathVariable 애너테이션으로 처리해 줄 수 있는 부분이다. 이처럼, URI에 파라미터를 포함시킨 요청을 @PathVariable 애너테이션을 사용하여 처리할 수 있다. @RestController public class MemberController { @GetMapping("/member/{id}/{name}") public String findM..
-
Spring Boot - @ModelAttribute의 사용방법 및 주의사항Framework & Library/Spring Boot 2022. 3. 23. 11:44
@ModelAttribute @ModelAttribute란? Spring 프레임워크 환경에서 Request Parameter를 얻기 위해 "@ModelAttribute" 애너테이션을 자주 사용한다. 해당 애너테이션은 파라미터로 넘어온 값을 바인딩하여 개발자가 원하는 객체로 변환해주는 역할을 수행한다. 문제 상황 @Getter public class Person { private String name; private Long age; } 값을 바인딩하기 위한 객체인 Person 클래스는 name과 age 필드 두 가지를 가지고 있다. @RequestMapping(value = "/getPerson.do", method = RequestMethod.GET) public String reqUrl(@ModelA..