java - @PathParam = null

标签 java rest jax-rs

嗨,我已经检查了很多帖子,但我还没有发现我遇到的问题。我的 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/

相关文章:

java - joinPoint 中的 getAnnotations 方法未列出该方法的注释之一

javascript - 使用 JSON 维护 RESTful url 的正确 Angularjs 方法

spring - 如何在Spring的REST Api中的rest调用中发送密码字符串?

java - 如何在一个 Spring Boot 应用程序中提供 html 页面和 jaxrs 服务?

java - 如何在 JAX-RS 中设置响应 header ,以便用户看到 Excel 的下载弹出窗口?

java - 从jspinner中删除逗号

java - 如何将 JLabel 放在 JTextArea 后面?

javascript - 如何确定 Javascript 中字符串中表达式的类型?

jaxb - 为什么在 Jersey 中使用 mime 类型 application/xml 请求资源时出现 "invalid request"?

java - Java泛型的类型参数中的问号是什么意思?