2015-10-21 31 views
2

即使在客户端传递true,用布尔参数调用REST也会收到值false@QueryParam即使通过'true'也会得到false

客户:

$http.post("http://localhost/getServers/?light=true") 

服务器:

@Path("/getServers") 
@POST 
@Produces({MediaType.APPLICATION_JSON}) 
public Response getServers(
    @Context HttpServletRequest request, 
    @DefaultValue("true") @QueryParam("light") boolean light) 
{ 
    // light is false even though true was passed 
    ... 
} 

回答

2

看来这个问号之前的斜线(/)(?)是问题。

删除客户端的斜杠后,一切正常。

这工作:

$http.post("http://localhost/getServers?light=true") 

,但是从阅读在网络上,一个问号之前的斜线是一个合法的语法:(

+1

它是在一个普通的HTTP请求合法的,但不是合同你写道,即'@Path(“/ getServers”)'不同于'@Path(“/ getServers /”)'。 –

相关问题