SpringMvc注解@PathVariable

6次阅读
没有评论

 

@PathVariable是spring3.0的一个新功能:接收请求路径中占位符的值

 

用法:

        @RequestMapping("/test/{id}/{name}")
        //返回JSON数据
		@ResponseBody
		public String t1(@PathVariable("id")Integer ids,
				@PathVariable("name")String names) {
			return ids+names;
		}

SpringMvc注解@PathVariable

请求的{ }必须和@PathVariable中的value值相同如果ids为id则可以省略value

@RequestMapping("/test/{id}/{name}")
@ResponseBody
public String t1(@PathVariable Integer id,@PathVariable String name) {
			return id+name;
		}

 

SpringMvc注解@PathVariable

正文完
 0