Spring 如何在注释中使用枚举
嗨,我正在创建一个名为Spring 如何在注释中使用枚举,spring,spring-boot,api,spring-mvc,dropwizard,Spring,Spring Boot,Api,Spring Mvc,Dropwizard,嗨,我正在创建一个名为 getData(Request req) 请求类就像 @Data public class Request(){ @NotNull public int mobileNumber; @NotNull public int currentLocation; } 我想限制正在使用我的api的客户端从下面给出的枚举中传递当前位置。我怎样才能用涂鸦来达到这个目的呢。我在DropWizard框架中工作 public enum Location { Us, Canad
getData(Request req)
请求类就像
@Data
public class Request(){
@NotNull
public int mobileNumber;
@NotNull
public int currentLocation;
}
我想限制正在使用我的api的客户端从下面给出的枚举中传递当前位置。我怎样才能用涂鸦来达到这个目的呢。我在DropWizard框架中工作
public enum Location {
Us, Canada, India
}
您是否尝试过将
currentLocation
的类型设置为Location
?例如:
@数据
公共类请求(){
@NotNull
公共国际流动电话;
@NotNull
公共场所;
}
然后当一个用户发送一个请求时
{
手机号码:12234,
当前位置:“加拿大”
{
Dropwizard将为您将字符串映射到枚举中。如果用户试图发送一个不在枚举中的值,Dropwizard将给他们一个合适的400响应
您可能还想考虑“<代码> MaseNoMuth</代码>一个字符串的类型,一些电话号码从一个前导零开始,在映射到INT./P>中会被删除,为什么不在位置Enm类型字段中反序列化呢?