赞
踩
你可以使用@RequestMapping注解来将请求URL,如/appointments等,映射到整个类上或某个特定的处理器方法上。一般来说,类级别的注解负责将一个特定(或符合某种模式)的请求路径映射到一个控制器上,同时通过方法级别的注解来细化映射,即根据特定的HTTP请求方法(“GET”“POST”方法等)、HTTP请求中是否携带特定参数等条件,将请求映射到匹配的方法上。
可以在方法和类上使用 @Target({ElementType.TYPE, ElementType.METHOD})
* value() 和 path()等返回值为字符串数组 都可以同时定义多个字符串值来接收多个URL请求
- @Target({ElementType.TYPE, ElementType.METHOD})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Mapping
- public @interface RequestMapping {
- String name() default "";
-
- @AliasFor("path")
- String[] value() default {};
-
- @AliasFor("value")
- String[] path() default {};
-
- RequestMethod[] method() default {};
-
- String[] params() default {};
-
- String[] headers() default {};
-
- String[] consumes() default {};
-
- String[] produces() default {};
- }
- @Target({ElementType.METHOD})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @RequestMapping(
- method = {RequestMethod.POST}
- )
- public @interface PostMapping {
- @AliasFor(
- annotation = RequestMapping.class
- )
- String name() default "";
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] value() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] path() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] params() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] headers() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] consumes() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] produces() default {};
- }
等于是@RequestMapping(value = "/", method = RequestMethod.POST)的缩写
- @Target({ElementType.METHOD})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @RequestMapping(
- method = {RequestMethod.GET}
- )
- public @interface GetMapping {
- @AliasFor(
- annotation = RequestMapping.class
- )
- String name() default "";
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] value() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] path() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] params() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] headers() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] consumes() default {};
-
- @AliasFor(
- annotation = RequestMapping.class
- )
- String[] produces() default {};
- }
等于是@RequestMapping(value = "/", method = RequestMethod.GET)的缩写
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。