嗨,我已经检查了很多帖子,但我还没有发现我遇到的问题。我的 PathParam 总是为空,谁能告诉我可能是什么问题
界面中的导入:
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
界面:
@RequestMapping(value="/unhash/{hash}", method = RequestMethod.GET)
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResponseBody
Token decryptToken(@PathParam("hash") String token, HttpServletRequest request) throws APIException;
以及实现:
@Override
public Token decryptToken(String token, HttpServletRequest request) throws APIException {
我在这里没有看到任何奇怪的东西,它对于查询参数工作得很好。有任何想法吗?我很困惑。
最佳答案
您如何调用您的服务以及为什么发送 HttpServletRequest 参数?我使用 Jersey 实现了您的场景,但没有 HttpServletRequest。我用 service/unhash/xxx 调用了服务。它工作得很好。
@Path("/service")
public class MyFirstRestService implements Rest {
@Override
public Response decryptToken(String token) throws Exception {
// TODO Auto-generated method stub
String output="It is success- Path Pram : "+ token;
return Response.ok(output).build();
}
休息类:
public interface Rest {
@GET
@Path(value="/unhash/{hash}")
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
Response decryptToken(@PathParam("hash") String token) throws Exception;
}
转到http://www.javawebservice.com了解更多信息和示例
关于java - @PathParam = null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33694723/