Missing URI template variable ‘employeeNumber‘ for method parameter of type String
程序员文章站
2022-07-15 13:11:22
...
使用SpringMVC参数注解@PathVariable时出错提示:
Missing URI template variable ‘employeeNumber’ for method parameter of type String
/**
* 通用上传请求
*/
@PostMapping("/common/upload1")
@ResponseBody
public AjaxResult uploadFile(List<MultipartFile> file, @PathVariable ("merNo") String merNo) throws Exception
{
try
{
.....
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
- 如果@RequestMapping中表示为”item/{id}”,id和形参名称一致,@PathVariable不用指定名称。如果不一致,例如”item/{ItemId}”则需要指定名称@PathVariable(“itemId”)。
- 因此原代码中的参数@RequestMapping(value = "/findUserByEmployeeNumber/{EmployeeNumber}中{EmployeeNumber}变量名需要和@PathVariable @Valid String employeeNumber中一样
修改办法:
1、方法一:修改PostMapping,带参数
@PostMapping("/common/upload1/{merNo}")
@ResponseBody
public AjaxResult uploadFile(List<MultipartFile> file, @PathVariable ("merNo") String merNo) throws Exception
{
try
{
.....
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
2、方法二:将 @PathVariable 修改为@RequestParam
/**
* 通用上传请求
*/
@PostMapping("/common/upload1")
@ResponseBody
public AjaxResult uploadFile(List<MultipartFile> file, @RequestParam("merNo") String merNo) throws Exception
{
try
{
....
AjaxResult ajax = AjaxResult.success();
/* ajax.put("fileName", fileName);
ajax.put("url", url);*/
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
注意两个区别
@PathVariable是获取url上数据的。
@RequestParam获取请求参数的(包括post表单提交)
推荐阅读
-
SpringBoot报错:Missing URI template variable 'XX' for method parameter of type XX
-
SpringMVC-Missing URI template variable 'id' for method parameter of type String
-
Missing URI template variable ‘id‘ for method parameter of type int[已解决]
-
Missing URI template variable 'employeeNumber' for method parameter of type String
-
springmvc:错误Missing URI template variable XX for method parameter of type String
-
Missing URI template variable 'XXXX' for method parameter of type String
-
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
-
Missing matrix variable 'XXX' for method parameter of type XXX