不能在方法内部使用注解

Can't use annotation inside method

我正在使用 jersey 在我的产品中实现 REST api 服务。为了获取表单参数值,我试图在我的方法中使用 @FormParam 注释。但在 Eclipse 中它抛出错误 "The annotation @FormParam is disallowed for this location".

如何修复此错误?

不要在方法中放置注释。注释通常放在前面:

  • 方法和构造函数
  • 方法参数

(however, more possibilities are available)

在你的情况下,annotate a parameter

public String addUser(@FormParam("emailid") String emailid, 
                      @FormParam("password") String password) {
   ...
}

这使得 request.getParameter(...) 不再需要。

Check a full example.