Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何在注释中使用枚举_Spring_Spring Boot_Api_Spring Mvc_Dropwizard - Fatal编程技术网

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类型字段中反序列化呢?