본문 바로가기
Http

GET / POST 를 목적에 맞춰 사용하지 못한 케이스

by ybs 2021. 6. 18.
반응형

1. 메뉴 클릭이고 화면 조회니까 get 이어야 하는데, jquery datatable 을 통해 만들어진, query string 이 너무 많아져서 limit 을 초과하는 에러가 발생했고 부득이 post 로 전송.

 

2. 앵귤러에서 # 를 스펙에 맞지 않게 사용함. 앵귤러는 url anchor 로써 동작이 아니라 앞부분에 붙여서 의도적으로 뒤에 path를 짜르도록 함. 그래서 url 에서 # 이후를 짤라버려서 request param 정보를 보낼 수 가 없어서 부득이 post 로 전송 (https://codecraft.tv/courses/angular/routing/routing-strategies/#_hashlocationstrategy)

 

3. 기존 시스템을 재개발하는 상황에서, 하위호환성을 맞춰야 하는 경우

 

아래와 같이 RequestMapping 애노테이션에 method 가 지정이 안되어있고, RequestParam 애노테이션으로 받도록 되어 있을 때

@RequestMapping(value = "/hello")
public String hello(
	@RequestParam(value = "id") String id,
    @RequestParam(value = "name") String name,
    @RequestParam(value = "number") String number) {
    
}

 

GET 으로 url query parameter 도 가능하고,

POST 로 url query parameter 도 가능하고,
POST 로 body 에 key=value 형태의 form data(application/x-www-form-urlencoded) 로 전달해도 가능.

 

Supported for annotated handler methods in Spring MVC and Spring WebFlux as follows: In Spring MVC, "request parameters" map to query parameters, form data, and parts in multipart requests. This is because the Servlet API combines query parameters and form data into a single map called "parameters", and that includes automatic parsing of the request body. In Spring WebFlux, "request parameters" map to query parameters only. To work with all 3, query, form data, and multipart data, you can use data binding to a command object annotated with ModelAttribute.

 

cf) web flux 에서는 url query parameter 만 가능하다.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html

반응형