本文介绍了如何在Jersey/Spring中使用@QueryParam重载方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用@QueryParam重载一个方法,但是每次我尝试执行此代码时,它都会抛出:
I would like to overload a method with the @QueryParam but everytime I try to execute this code it throws:
SEVERE: Exception occurred when intialization
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
我的代码是:
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid)
{
return pid;
}
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid, @QueryParam("NAME") String name)
{
return pid + name;
}
推荐答案
不能.
在Java中还可以,但从servlet的角度来看,jersey需要将每个url映射到类中的某个函数.
It's ok in java, but the thing about it is - from the servlet side - jersey needs to map each url to some function in your class.
您可以做的当然是将其分为2种方法,或者构建一种检查参数并执行正确逻辑的方法.
What you can do is, of course, separate it into 2 methods, or build one method that checks the parameters and does the right logic.
这篇关于如何在Jersey/Spring中使用@QueryParam重载方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!