Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum as a part of path variable #205

Open
viartemev opened this issue Aug 27, 2019 · 1 comment
Open

Enum as a part of path variable #205

viartemev opened this issue Aug 27, 2019 · 1 comment
Assignees

Comments

@viartemev
Copy link
Owner

public enum  MediatekaPage {
    VIDEO("video"), AUDIO("audio"), PHOTO("photo");

    private String value;

    MediatekaPage(String value) {
        this.value = value;
    }
}
@GetMapping("/{page}")
getMediatekaPage(@PathVariable MediatekaPage page)

@viartemev viartemev self-assigned this Aug 27, 2019
@viartemev viartemev added this to the 0.15.0 release milestone Aug 27, 2019
@viartemev
Copy link
Owner Author

There are places where binding can be done:

  1. With annotation @InitBinder
@InitBinder
public void initBinder(final WebDataBinder webdataBinder) {
    webdataBinder.registerCustomEditor(QuestionCategory.class, new QuestionCategoryConverter());
}
  1. 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());
    }
}

@viartemev viartemev removed this from the 0.2.0 release milestone May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant