当前位置:网站首页>Missing URI template variable ‘employeeNumber‘ for method parameter of type String
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
2022-08-09 10:50:00 【天T.】
使用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表单提交)
边栏推荐
猜你喜欢
随机推荐
AQS同步组件-FutureTask解析和用例
cnn的输入输出
unix环境编程 第十五章 15.10 POSIX信号量
华为VRRP+MSTP联动接口检测实验案例
彻底理解工厂模式
unix环境编程 第十四章 14.8 存储映射I/O
TensorFlow—计算梯度与控制梯度 : tf.gradients和compute_gradients和apply_gradients和clip_by_global_norm控制梯度
activemq 消息持久化
caffe ---make all editing error
深度学习--生成对抗网络(Generative Adversarial Nets)
Electron application development best practices
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only
UNIX Environment Programming Chapter 15 15.5FIFO
为什么组合优先于继承
强化学习 (Reinforcement Learning)
信息系统项目的十大管理
Invisible OOM in kubernetes
ESIM(Enhanced Sequential Inference Model)- 模型详解
批量转换经纬度的网页实现方法
cesium加载地图