问题描述:
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
问题分析:
1、使用Swagger调试地址栏传参的接口时,参数类型paramType设置为query,导致调用接口报错。
@DeleteMapping("delete/{id}")
@ApiOperation(value = "删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ID", paramType = "query", dataType = "Long", required = true)
})
public String delete(@PathVariable("id") Long id){
return "";
}
解决办法:将paramType设置为path,代表地址栏传参。
@DeleteMapping("delete/{id}")
@ApiOperation(value = "删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ID", paramType = "path", dataType = "Long", required = true)
})
public String delete(@PathVariable("id") Long id){
return "";
}
2、后端接口