转自:
下文笔者将讲述@pathVariable注解的功能简介说明,如下所示:
@pathVariable注解的功能
@PathVariable注解简介: @PathVariable是spring3.0的一个新功能 它用于接收请求路径中占位符的值
@PathVariable注解的功能
@PathVariable("xxx") 通过 @PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariable(“xxx“) @RequestMapping(value=”user/{id}/{name}”) 请求路径:http://localhost:8080/hello/test/1/maomao
例:
package com.day01springmvc.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; /** * @ Author :java265.com */ @Controller @RequestMapping("hello") public class HelloController2 { /** *3、占位符映射 * 语法:@RequestMapping(value=”user/{userId}/{userName}”) * 请求路径:http://localhost:8080/hello/test/1/maomao * @param ids * @param names * @return */ @RequestMapping("test/{id}/{name}") public ModelAndView test5(@PathVariable("id") Long ids ,@PathVariable("name") String names){ ModelAndView mv = new ModelAndView(); mv.addObject("msg","占位符映射:id:"+ids+";name:"+names); mv.setViewName("tttttt"); return mv; } }