@PathVariable是什么鬼?
什么是@PathVariable?请看源码:
/**
* Annotation which indicates that a method parameter should be bound to a URI template
* variable. Supported for {@link RequestMapping} annotated handler methods in Servlet
* environments.
* <p>If the method parameter is {@link java.util.Map Map<String, String>} or
* {@link org.springframework.util.MultiValueMap MultiValueMap<String, String>}
* then the map is populated with all path variable names and values.
* @author Arjen Poutsma
* @since 3.0
* @see RequestMapping
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
*/
1、这是一个注解,用来指明一个路径参数(method),这个参数必须被跟一个URI实例变量绑定,被支持于 {@RequestMapping},在一个servlet环境中注释处理方法;
2、如果路径参数是{@link java.util.Map Map<String,String>},接着,这个映射就会随着所有的路径变量名字和值构成;
作者:Arjen Poutsma
自从:版本3.0
请看:RequestMapping
请看:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
请看:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PathVariable {
/**
* The URI template variable to bind to.
*/
String value() default "";
}
1、对象:ElementType.PARAMEER
2、有效期:有效期政策.运行时
3、文档登记过了;(哈哈)
定义了一个公共的注解PathVariable,路径变量;
和URI实例变量绑定;
String类型的值,默认为“”