我的URL请求是http://localhost:8080/login/verify/212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=
我需要得到以下部分:**212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=**。
以下代码不起作用:
@RequestMapping(value = "/login/verify/{request:.+}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public ResponseEntity verifyLogin(@PathVariable(value = "request") String request)
throws InvalidSignatureException
{
}错误: HTTP状态404。
Spring无法处理此请求。
发布于 2017-05-17 06:43:20
若要将uri与斜杠匹配,请使用double *
@RequestMapping(value = "/login/verify/**",然后,在正文中获取值,您将使用
String str = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)样本代码:
@RequestMapping(value = "/login/verify/**", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public ResponseEntity verifyLogin(HttpServletRequest httpServletRequest) throws InvalidSignatureException {
String str = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)
}发布于 2017-05-17 05:20:29
尝试以下网址:http://localhost:8080/login/verify?req=212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=
像这样处理它:
@RequestMapping("/login/verify")
public String test(@RequestParam("req") String data) {
//'data' will contains '212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo='
String params[] = data.split(",");
}发布于 2017-05-17 06:26:01
您的url中有正斜杠,这些字符串将被视为路径变量。如果有可能只有3个路径变量,请尝试下面的代码。请看一下here和here
@RequestMapping(value = {"/login/verify/{string1:.+}",
"/login/verify/{string1:.+}/{string2:.+}",
"/login/verify/{string1:.+}/{string2:.+}/{string3:.+}"}, method = RequestMethod.POST)
public ResponseEntity verifyLogin(HttpServletRequest request, HttpServletResponse httpresponse,
@PathVariable("string1") String string1,
@PathVariable("string2") String string2,
@PathVariable("string3") String string3) {
System.out.println("***************************************************I am called: "+string1+" "+string2+" "+string3);}
https://stackoverflow.com/questions/44015637
复制相似问题