틀린 해석이 있다면 알려주세요
@ModelAttribute 사용
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, "Spring Web MVC," comes from the name of its source module (spring-webmvc), but it is more commonl
docs.spring.io
@RequestMapping 을 생성하거나, WebDataBinder 를 통해 Object에 접근
메서드 호출 전에 모델 초기화 -> @Controller, @ControllerAdvice
@RequestMapping 에는 모델 속성이 있음
controller 는 여러개의 @ModelAttribute 를 가질 수 있음
컨트롤러간 공유도 가능함 -> @ControllerAdvice 를 이용
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, "Spring Web MVC," comes from the name of its source module (spring-webmvc), but it is more commonl
docs.spring.io
model 추가
@ModelAttribute
public void populateModel(@RequestParam String number, Model model) {
model.addAttribute(accountRepository.findAccount(number));
// add more ...
}
attribute 하나만 추가하기
@ModelAttribute
public Account addAccount(@RequestParam String number) {
return accountRepository.findAccount(number);
}
이름이 명시되어있지 않으면 기본 이름이 선택됨
Conventions (Spring Framework 6.0.4 API)
Determine the conventional variable name for the given parameter taking the generic collection type, if any, into account. Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into ac
docs.spring.io
이름 정의 하는 방법
@GetMapping("/accounts/{id}")
@ModelAttribute("myAccount")
public Account handle() {
// ...
return account;
}
'Web > spring' 카테고리의 다른 글
[Spring framework Web MVC docs] 1.3.7 ControllerAdvice (0) | 2023.02.02 |
---|---|
[Spring framework Web MVC docs] 1.3.5 DataBinder ~ 1.3.6 Exception (0) | 2023.02.02 |
[Spring framework Web MVC docs] 1.3.3 Handler Methods (0) | 2023.02.01 |
[Spring framework Web MVC docs] 1.3.2 Request Mapping (0) | 2023.02.01 |
[Spring error] error print properties (0) | 2023.01.25 |