til
til copied to clipboard
Spring comma-delimited parameter
다음과 같은 API 에 id=1,2,3
을 전달하면 ,
로 구분된 값이 각각 저장된다.
@GetMapping("/api/foos")
@ResponseBody
public String getFoos(@RequestParam List<String> id) {
return "IDs are " + id;
}
http://localhost:8080/api/foos?id=1,2,3
----
IDs are [1,2,3]
List<CustomType> types
와 같은 형식으로 사용하고 싶은 경우 다음과 같이 Converter
를 구현한 컨버터를 등록해서 사용한다.
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new CustomTypeConverter());
}
}