본문 바로가기
프로그래밍/Spring

@RequestParam(required = false)

by 이잭 2024. 12. 17.
@RequestParam(value = "name", required = false) String name, Model model

 

 

더보기
더보기

참고

@RequestParam

Spring MVC에서 쿼리 스트링 정보를 쉽게 가져오는데 사용할 수 있다.

 

 

@RequestParam이 적용된 필드가 없으면 Bad Request, Required String parameter 'name' is not present 라는 예외를 발생시킨다.

 

기본 요청 : http://localhost:8080/hello-mvc?name=이름

required = false http://localhost:8080/hello-mvc 여기까지만 넣어도 가능하게 해준다.

(default가 true이니까 원래는 뒤에 파라미터를 넣지 않으면 오류)

 

 

'프로그래밍 > Spring' 카테고리의 다른 글

어노테이션(@RequestMapping, @RequestParam)  (0) 2024.12.17