Skip to content

Commit 16c5952

Browse files
committed
Add and improve Spring-web stubs
1 parent ed054ac commit 16c5952

File tree

4 files changed

+655
-14
lines changed

4 files changed

+655
-14
lines changed
Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2002-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.web.bind.annotation;
218

319
import java.lang.annotation.Documented;
@@ -6,11 +22,69 @@
622
import java.lang.annotation.RetentionPolicy;
723
import java.lang.annotation.Target;
824

25+
import org.springframework.core.annotation.AliasFor;
26+
27+
/**
28+
* Annotation for mapping HTTP {@code POST} requests onto specific handler
29+
* methods.
30+
*
31+
* <p>Specifically, {@code @PostMapping} is a <em>composed annotation</em> that
32+
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.POST)}.
33+
*
34+
* @author Sam Brannen
35+
* @since 4.3
36+
* @see GetMapping
37+
* @see PutMapping
38+
* @see DeleteMapping
39+
* @see PatchMapping
40+
* @see RequestMapping
41+
*/
942
@Target(ElementType.METHOD)
1043
@Retention(RetentionPolicy.RUNTIME)
1144
@Documented
1245
@RequestMapping(method = RequestMethod.POST)
1346
public @interface PostMapping {
1447

15-
String[] value() default {};
16-
}
48+
/**
49+
* Alias for {@link RequestMapping#name}.
50+
*/
51+
@AliasFor(annotation = RequestMapping.class)
52+
String name() default "";
53+
54+
/**
55+
* Alias for {@link RequestMapping#value}.
56+
*/
57+
@AliasFor(annotation = RequestMapping.class)
58+
String[] value() default {};
59+
60+
/**
61+
* Alias for {@link RequestMapping#path}.
62+
*/
63+
@AliasFor(annotation = RequestMapping.class)
64+
String[] path() default {};
65+
66+
/**
67+
* Alias for {@link RequestMapping#params}.
68+
*/
69+
@AliasFor(annotation = RequestMapping.class)
70+
String[] params() default {};
71+
72+
/**
73+
* Alias for {@link RequestMapping#headers}.
74+
*/
75+
@AliasFor(annotation = RequestMapping.class)
76+
String[] headers() default {};
77+
78+
/**
79+
* Alias for {@link RequestMapping#consumes}.
80+
*/
81+
@AliasFor(annotation = RequestMapping.class)
82+
String[] consumes() default {};
83+
84+
/**
85+
* Alias for {@link RequestMapping#produces}.
86+
*/
87+
@AliasFor(annotation = RequestMapping.class)
88+
String[] produces() default {};
89+
90+
}
Lines changed: 189 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,209 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.web.bind.annotation;
218

319
import java.lang.annotation.Documented;
420
import java.lang.annotation.ElementType;
521
import java.lang.annotation.Retention;
622
import java.lang.annotation.RetentionPolicy;
723
import java.lang.annotation.Target;
24+
825
import org.springframework.core.annotation.AliasFor;
926

10-
@Target(value={ElementType.METHOD,ElementType.TYPE})
11-
@Retention(value=RetentionPolicy.RUNTIME)
27+
/**
28+
* Annotation for mapping web requests onto methods in request-handling classes
29+
* with flexible method signatures.
30+
*
31+
* <p>Both Spring MVC and Spring WebFlux support this annotation through a
32+
* {@code RequestMappingHandlerMapping} and {@code RequestMappingHandlerAdapter}
33+
* in their respective modules and package structure. For the exact list of
34+
* supported handler method arguments and return types in each, please use the
35+
* reference documentation links below:
36+
* <ul>
37+
* <li>Spring MVC
38+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-arguments">Method Arguments</a>
39+
* and
40+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-return-types">Return Values</a>
41+
* </li>
42+
* <li>Spring WebFlux
43+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-ann-arguments">Method Arguments</a>
44+
* and
45+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-ann-return-types">Return Values</a>
46+
* </li>
47+
* </ul>
48+
*
49+
* <p><strong>Note:</strong> This annotation can be used both at the class and
50+
* at the method level. In most cases, at the method level applications will
51+
* prefer to use one of the HTTP method specific variants
52+
* {@link GetMapping @GetMapping}, {@link PostMapping @PostMapping},
53+
* {@link PutMapping @PutMapping}, {@link DeleteMapping @DeleteMapping}, or
54+
* {@link PatchMapping @PatchMapping}.</p>
55+
*
56+
* <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
57+
* make sure to consistently put <i>all</i> your mapping annotations - such as
58+
* {@code @RequestMapping} and {@code @SessionAttributes} - on
59+
* the controller <i>interface</i> rather than on the implementation class.
60+
*
61+
* @author Juergen Hoeller
62+
* @author Arjen Poutsma
63+
* @author Sam Brannen
64+
* @since 2.5
65+
* @see GetMapping
66+
* @see PostMapping
67+
* @see PutMapping
68+
* @see DeleteMapping
69+
* @see PatchMapping
70+
*/
71+
@Target({ElementType.TYPE, ElementType.METHOD})
72+
@Retention(RetentionPolicy.RUNTIME)
1273
@Documented
1374
@Mapping
1475
public @interface RequestMapping {
15-
String name() default "";
1676

17-
@AliasFor("path")
18-
String[] value() default {};
77+
/**
78+
* Assign a name to this mapping.
79+
* <p><b>Supported at the type level as well as at the method level!</b>
80+
* When used on both levels, a combined name is derived by concatenation
81+
* with "#" as separator.
82+
* @see org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder
83+
* @see org.springframework.web.servlet.handler.HandlerMethodMappingNamingStrategy
84+
*/
85+
String name() default "";
86+
87+
/**
88+
* The primary mapping expressed by this annotation.
89+
* <p>This is an alias for {@link #path}. For example,
90+
* {@code @RequestMapping("/foo")} is equivalent to
91+
* {@code @RequestMapping(path="/foo")}.
92+
* <p><b>Supported at the type level as well as at the method level!</b>
93+
* When used at the type level, all method-level mappings inherit
94+
* this primary mapping, narrowing it for a specific handler method.
95+
* <p><strong>NOTE</strong>: A handler method that is not mapped to any path
96+
* explicitly is effectively mapped to an empty path.
97+
*/
98+
@AliasFor("path")
99+
String[] value() default {};
100+
101+
/**
102+
* The path mapping URIs (e.g. {@code "/profile"}).
103+
* <p>Ant-style path patterns are also supported (e.g. {@code "/profile/**"}).
104+
* At the method level, relative paths (e.g. {@code "edit"}) are supported
105+
* within the primary mapping expressed at the type level.
106+
* Path mapping URIs may contain placeholders (e.g. <code>"/${profile_path}"</code>).
107+
* <p><b>Supported at the type level as well as at the method level!</b>
108+
* When used at the type level, all method-level mappings inherit
109+
* this primary mapping, narrowing it for a specific handler method.
110+
* <p><strong>NOTE</strong>: A handler method that is not mapped to any path
111+
* explicitly is effectively mapped to an empty path.
112+
* @since 4.2
113+
*/
114+
@AliasFor("value")
115+
String[] path() default {};
19116

20-
@AliasFor("value")
21-
String[] path() default {};
117+
/**
118+
* The HTTP request methods to map to, narrowing the primary mapping:
119+
* GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE.
120+
* <p><b>Supported at the type level as well as at the method level!</b>
121+
* When used at the type level, all method-level mappings inherit this
122+
* HTTP method restriction.
123+
*/
124+
RequestMethod[] method() default {};
22125

23-
RequestMethod[] method() default {};
126+
/**
127+
* The parameters of the mapped request, narrowing the primary mapping.
128+
* <p>Same format for any environment: a sequence of "myParam=myValue" style
129+
* expressions, with a request only mapped if each such parameter is found
130+
* to have the given value. Expressions can be negated by using the "!=" operator,
131+
* as in "myParam!=myValue". "myParam" style expressions are also supported,
132+
* with such parameters having to be present in the request (allowed to have
133+
* any value). Finally, "!myParam" style expressions indicate that the
134+
* specified parameter is <i>not</i> supposed to be present in the request.
135+
* <p><b>Supported at the type level as well as at the method level!</b>
136+
* When used at the type level, all method-level mappings inherit this
137+
* parameter restriction.
138+
*/
139+
String[] params() default {};
24140

25-
String[] params() default {};
141+
/**
142+
* The headers of the mapped request, narrowing the primary mapping.
143+
* <p>Same format for any environment: a sequence of "My-Header=myValue" style
144+
* expressions, with a request only mapped if each such header is found
145+
* to have the given value. Expressions can be negated by using the "!=" operator,
146+
* as in "My-Header!=myValue". "My-Header" style expressions are also supported,
147+
* with such headers having to be present in the request (allowed to have
148+
* any value). Finally, "!My-Header" style expressions indicate that the
149+
* specified header is <i>not</i> supposed to be present in the request.
150+
* <p>Also supports media type wildcards (*), for headers such as Accept
151+
* and Content-Type. For instance,
152+
* <pre class="code">
153+
* &#064;RequestMapping(value = "/something", headers = "content-type=text/*")
154+
* </pre>
155+
* will match requests with a Content-Type of "text/html", "text/plain", etc.
156+
* <p><b>Supported at the type level as well as at the method level!</b>
157+
* When used at the type level, all method-level mappings inherit this
158+
* header restriction.
159+
* @see org.springframework.http.MediaType
160+
*/
161+
String[] headers() default {};
26162

27-
String[] headers() default {};
163+
/**
164+
* Narrows the primary mapping by media types that can be consumed by the
165+
* mapped handler. Consists of one or more media types one of which must
166+
* match to the request {@code Content-Type} header. Examples:
167+
* <pre class="code">
168+
* consumes = "text/plain"
169+
* consumes = {"text/plain", "application/*"}
170+
* consumes = MediaType.TEXT_PLAIN_VALUE
171+
* </pre>
172+
* Expressions can be negated by using the "!" operator, as in
173+
* "!text/plain", which matches all requests with a {@code Content-Type}
174+
* other than "text/plain".
175+
* <p><b>Supported at the type level as well as at the method level!</b>
176+
* If specified at both levels, the method level consumes condition overrides
177+
* the type level condition.
178+
* @see org.springframework.http.MediaType
179+
* @see javax.servlet.http.HttpServletRequest#getContentType()
180+
*/
181+
String[] consumes() default {};
28182

29-
String[] consumes() default {};
183+
/**
184+
* Narrows the primary mapping by media types that can be produced by the
185+
* mapped handler. Consists of one or more media types one of which must
186+
* be chosen via content negotiation against the "acceptable" media types
187+
* of the request. Typically those are extracted from the {@code "Accept"}
188+
* header but may be derived from query parameters, or other. Examples:
189+
* <pre class="code">
190+
* produces = "text/plain"
191+
* produces = {"text/plain", "application/*"}
192+
* produces = MediaType.TEXT_PLAIN_VALUE
193+
* produces = "text/plain;charset=UTF-8"
194+
* </pre>
195+
* <p>If a declared media type contains a parameter (e.g. "charset=UTF-8",
196+
* "type=feed", "type=entry") and if a compatible media type from the request
197+
* has that parameter too, then the parameter values must match. Otherwise
198+
* if the media type from the request does not contain the parameter, it is
199+
* assumed the client accepts any value.
200+
* <p>Expressions can be negated by using the "!" operator, as in "!text/plain",
201+
* which matches all requests with a {@code Accept} other than "text/plain".
202+
* <p><b>Supported at the type level as well as at the method level!</b>
203+
* If specified at both levels, the method level produces condition overrides
204+
* the type level condition.
205+
* @see org.springframework.http.MediaType
206+
*/
207+
String[] produces() default {};
30208

31-
String[] produces() default {};
32209
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2002-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.bind.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.core.annotation.AliasFor;
26+
import org.springframework.stereotype.Controller;
27+
28+
/**
29+
* A convenience annotation that is itself annotated with
30+
* {@link Controller @Controller} and {@link ResponseBody @ResponseBody}.
31+
* <p>
32+
* Types that carry this annotation are treated as controllers where
33+
* {@link RequestMapping @RequestMapping} methods assume
34+
* {@link ResponseBody @ResponseBody} semantics by default.
35+
*
36+
* <p><b>NOTE:</b> {@code @RestController} is processed if an appropriate
37+
* {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the
38+
* {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter}
39+
* pair which are the default in the MVC Java config and the MVC namespace.
40+
*
41+
* @author Rossen Stoyanchev
42+
* @author Sam Brannen
43+
* @since 4.0
44+
*/
45+
@Target(ElementType.TYPE)
46+
@Retention(RetentionPolicy.RUNTIME)
47+
@Documented
48+
@Controller
49+
@ResponseBody
50+
public @interface RestController {
51+
52+
/**
53+
* The value may indicate a suggestion for a logical component name,
54+
* to be turned into a Spring bean in case of an autodetected component.
55+
* @return the suggested component name, if any (or empty String otherwise)
56+
* @since 4.0.1
57+
*/
58+
@AliasFor(annotation = Controller.class)
59+
String value() default "";
60+
61+
}

0 commit comments

Comments
 (0)