欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springmvc:错误Missing URI template variable XX for method parameter of type String

程序员文章站 2022-07-15 13:12:34
...

springmvc:错误Missing URI template variable ‘userId’ for method parameter of type String

springmvc:错误Missing URI template variable XX for method parameter of type String
错误写法:
springmvc:错误Missing URI template variable XX for method parameter of type String
正确:
springmvc:错误Missing URI template variable XX for method parameter of type String

知识点@PathVariable注解:

关于路径变量和模板参数:

  • {id}:路径变量(模板参数)

@PathVariable:

  1. 作用:把路径变量的值,绑定到方法的形参上 该注解的常见写法:
@PathVariable(name = "id")
@PathVariable(value = "id")
@PathVariable("id")
  1. 以下两种写法的前提是:路径变量的名称,与方法形参的名称一样
@PathVariable()
@PathVariable

综合

@RequestMapping(value = {"item/{id}"},method = {RequestMethod.GET}) @ResponseBody 
public Item get(@PathVariable Integer id){
 // 创建商品对象 
 Item item = new Item(); 
 item.setId(id); 
 item.setName("查询商品"); 
 return item; 
 }
相关标签: java spring