@PathVariable注解的功能是什么呢?
作者:互联网
下文笔者将讲述@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; } }
转自:http://www.java265.com/JavaFramework/SpringMVC/202204/2800.html
标签:RequestMapping,功能,PathVariable,ModelAndView,注解,id,name 来源: https://www.cnblogs.com/java265/p/16120956.html