【发布时间】:2017-09-04 12:35:29
【问题描述】:
我收到以下编译错误:
Error(35,13): annotation type not applicable to this kind of declaration
Error(36,13): annotation type not applicable to this kind of declaration
Error(38,13): annotation type not applicable to this kind of declaration
Error(39,13): annotation type not applicable to this kind of declaration
Error(41,13): annotation type not applicable to this kind of declaration
Error(42,13): annotation type not applicable to this kind of declaration
所有这些错误都是针对来自 Jersey 的 @ParamValue 和 @DefaultValue 注释。我在互联网上看到了很多例子,他们都说 Jersey 允许字符串类和所有包装类。我不明白为什么它在这里不起作用。
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("/sracows")
public class sracoWebService {
public sracoWebService() {
super();
}
@GET
@Path("/empdata")
public String getEmployeeData() throws Exception {
try {
@DefaultValue("nationality")
@QueryParam("nationality")
String nationality;
@DefaultValue("experience")
@QueryParam("experience")
String experience;
@DefaultValue("empid")
@QueryParam("empid")
String empid;
} catch(Exception e){
e.printStackTrace();
}
}
}
【问题讨论】:
-
在getEmployeeData(@QueryParam("nationality") String nationality)等方法参数中使用