개발/Spring Boot Framework

spring boot에서 euc-kr 요청 받기

펭귀니 :) 2023. 10. 12. 17:58

 


import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import java.nio.charset.Charset;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class CustomMessageConverterConfig implements WebMvcConfigurer {

  @Override
  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    // 문자열 메시지 컨버터를 생성하고 EUC-KR 인코딩을 설정합니다.
    StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("EUC-KR"));
    converters.add(converter);
  }
}
 No newline at end of file

 

public class tmpController {

    @PostMapping(value = "/v1/tmp", consumes = "application/x-www-form-urlencoded; charset=euc-kr")
    public String request(@RequestBody MultiValueMap<String, String> request) {

        log.info(request.toString());

        return "success";
    }

}

'개발 > Spring Boot Framework' 카테고리의 다른 글

@Controller와 @RestController 차이점  (0) 2021.06.03
웹 애플리케이션 컨테이너  (0) 2019.12.18
Spring, Spring Boot란?  (0) 2019.12.11