티스토리 뷰

공부

[Spring] ignoreCase enum request parameter

승가비 2020. 11. 7. 07:59
728x90
@RestController
public class MyController {
    
    @GetMapping("/test/{myEnum}")
    public String getMyEnum(@PathVariable MyEnum myEnum) {
        return "Hey " + myEnum;
    }
}

public enum MyEnum {
    HEY,
    HELLO
}

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class MyEnumConverter implements Converter<String, MyEnum> {

    @Override
    public MyEnum convert(String value) {
        return MyEnum.valueOf(value.toUpperCase());
    }
}

https://vianneyfaivre.com/tech/spring-boot-enum-as-parameter-ignore-case

 

Spring Boot: How to ignore case when using an Enum as a Request parameter

Here is a way to enable the use of case-insensitive enumerations request parameters. You won’t need to do any code modification in your enum. Let’s say you have a controller class: @RestController public class MyController { @GetMapping("/test/{myEnum}

vianneyfaivre.com

 

728x90

'공부' 카테고리의 다른 글

[Link] regexr.com  (0) 2020.11.07
[Spark] array to multiple rows  (0) 2020.11.07
[Java] convert current `date` to `integer`  (0) 2020.11.07
[Docker] basic  (0) 2020.10.30
[Kotlin] `val` vs `var`  (0) 2020.10.28
댓글