Missing URI template variable 'employeeNumber' for method parameter of type String
2017-07-26 09:53
946 查看
使用SpringMVC参数注解@PathVariable时出错提示:
Missing URI template variable 'employeeNumber' for method parameter of type String
@RequestMapping(value = "/findUserByEmployeeNumber/{EmployeeNumber}",method = RequestMethod.GET) public ResponseEntity<TodoUser> findByNumber(@PathVariable @Valid String employeeNumber){ ... }
如果@RequestMapping中表示为”item/{id}”,id和形参名称一致,@PathVariable不用指定名称。如果不一致,例如”item/{ItemId}”则需要指定名称@PathVariable(“itemId”)。
因此原代码中的参数
@RequestMapping(value = "/findUserByEmployeeNumber/{EmployeeNumber}中{EmployeeNumber}变量名需要和
@PathVariable @Valid String employeeNumber中一样
修改后:
方法一:参数名一致
@RequestMapping(value = "/findUserByEmployeeNumber/{employeeNumber}",method = RequestMethod.GET) public ResponseEntity<TodoUser> findByNumber(@PathVariable @Valid String employeeNumber){ ... }
方法二:添加别名
@RequestMapping(value = "/findUserByEmployeeNumber/{employeeNumber}",method = RequestMethod.GET) public ResponseEntity<TodoUser> findByNumber(@PathVariable("employeeNumber") @Valid String Number){ ... }
注意两个区别
@PathVariable是获取url上数据的。
@RequestParam获取请求参数的(包括post表单提交)
更多SpringMVC用法详见本人博客SpringMVC02教程
Github项目使用SpringMVC总结
相关文章推荐
- could not find implicit value for evidence parameter of type TypeInformation[String]
- Parameter 'p_REMARK': No size set for variable length data type: String.
- No parameter name specified for argument of type [java.lang.String]
- The method queryForMap(String, Object...) from the type JdbcTemplate refers to the missing type DataAccessException
- No parameter name specified for argument of type [java.lang.String],
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- Parameter \' \': No size set for variable length data type: String
- 异常:There was no TypeHandler found for parameter id of statement
- The method create(Context, Uri) in the type MediaPlayer is not applicable for the arguments (new Vie
- The method isEmpty() is undefined for the type String/String类型的isEmpty报错
- (转)eclipse 报错 :The method list(String, Object[]) is ambiguous for the type BaseHibernateDao
- request for member 'getid’ in ‘e1’, which is of non-class type ‘Employee()’
- Name for argument type [java.lang.String] not available, and parameter name information not found in
- 解决Undefined function or method 'vgg_kmiter' for input arguments of type 'double'.
- 开发中碰到的问题:The method getSystemService(String) is undefined for the type CourseFragment
- Struts2 启动时报警告:no default parameter defined for result of type json
- The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)
- Could not find method android() for arguments on root project '项目名' of type org.gradle.api.Project.
- The template file for selected project type is missing的解决
- The method list(String, Object[]) is ambiguous for the type BaseHibernateDao<M,PK