My Spring-Controller的端点配置如下:
@ApiOperation(value = "Bla",response = String.class, responseContainer = "")
@ApiResponses(value = { /* some @ApiResponse error codes */ })
@SomeAspectAnnotation
@RequestTrace
@RequestMapping(
method = RequestMethod.GET,
value = "/{name}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<String> getBenutzereinstellungenByName(
@PathVariable() String name,
@ApiParam(name = "Authorization", value = "JWT", required = true) @RequestHeader(value = "Authorization") String jwt,
@ApiParam(name = "SomeParam", value = "Some Header Param") @RequestHeader(value = "Some-Param", required = false) String someParam
) {
return new ResponseEntity<>(name, HttpStatus.OK);
}
当我在最后用数字调用网址时,我得到1
作为邮递员的回复。当我用&#34; test&#34;来调用它时,服务器返回Unexpected 't'
。为什么? PathVariable的类型为String,RequestMapping中没有Regex限制
编辑:将
PathVariable()
更改为@PathVariable(value = "name", name = "name", required = true)
对问题没有帮助EDIT2:我改变了问题的标题。它可以关闭。问题在于,当邮递员期望应用程序/ json响应时,不需要
"no"
来获得答案,但1
将会这样做。
答案 0 :(得分:0)
关于映射正确调用路径变量
@GetMapping("/{name}")
public ResponseEntity<String> getBenutzers(@PathVariable("name") String name){
return new ResponseEntity<>(name, HttpStatus.OK);
}