2015-10-21 34 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 /」)'。 –

相關問題