Spring Boot RestController路径Variable字符串附加了引号



我正在使用一个带有get requestMapping的方法的Spring Boot RestController,并且使用字符串参数。参数必须从url路径范围映射到此类/方法/{param}。

@ResponseStatus(HttpStatus.OK)
RequestMapping(value = "/method/{param}", method = 
RequestMethod.GET)
public ResponseEntity findByName(@PathVariable String param){

logger.info(param);// this log has " before and after the string
String p  = StringEscapeUtils.unescapeHtml4(param);
logger.info(p); 

 ... 
 }  

http请求

    GET /SampleDataService/method/vanilla HTTP/1.1
    Host: localhost:8080
    Connection: keep-alive
    Pragma: no-cache
    Cache-Control: no-cache
    Upgrade-Insecure-Requests: 1    
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.8

我确实获得了值参数,但它的html逃脱了引号标记。

对于例如,如果我打电话给/method/vanilla,我得到"vanilla"

现在,我正在使用StringEscapeUtils.unescapeHtml4(param),然后用空字符串替换引号。但是我想知道是否有一些春季启动配置可以防止字符串路径上的额外报价。

在URL中具有多个参数

@RequestMapping(value="/method/{param:.+}", method=RequestMethod.GET)
public ResponseEntity findByName(@PathVariable("param")String param){
 ....
}

最新更新