requestmapper
requestmapper copied to clipboard
Enum as a part of path variable
public enum MediatekaPage {
VIDEO("video"), AUDIO("audio"), PHOTO("photo");
private String value;
MediatekaPage(String value) {
this.value = value;
}
}
@GetMapping("/{page}")
getMediatekaPage(@PathVariable MediatekaPage page)
There are places where binding can be done:
- With annotation
@InitBinder
@InitBinder
public void initBinder(final WebDataBinder webdataBinder) {
webdataBinder.registerCustomEditor(QuestionCategory.class, new QuestionCategoryConverter());
}
- Extends from
Converter:
public class StringToEnumConverter implements Converter<String, Modes> {
@Override
public Modes convert(String from) {
return Modes.valueOf(from);
}
}
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringToEnumConverter());
}
}