Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c121f460
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c121f460
编写于
6月 07, 2016
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Document composed @RequestMapping variants in the reference manual
Issue: SPR-13995
上级
31aed61d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
7 deletion
+64
-7
src/asciidoc/web-mvc.adoc
src/asciidoc/web-mvc.adoc
+63
-7
src/asciidoc/whats-new.adoc
src/asciidoc/whats-new.adoc
+1
-0
未找到文件。
src/asciidoc/web-mvc.adoc
浏览文件 @
c121f460
...
...
@@ -611,12 +611,12 @@ application that uses this annotation:
}
----
In the
example, the
`@RequestMapping` is used in a number of places. The first usage is
on the type (class) level, which indicates that all handl
ing methods o
n this controller
In the
above example,
`@RequestMapping` is used in a number of places. The first usage is
on the type (class) level, which indicates that all handl
er methods i
n this controller
are relative to the `/appointments` path. The `get()` method has a further
`@RequestMapping` refinement: it only accepts
GET requests, meaning that an HTTP GET
for
`@RequestMapping` refinement: it only accepts
`GET` requests, meaning that an HTTP `GET`
for
`/appointments` invokes this method. The `add()` has a similar refinement, and the
`getNewForm()` combines the definition of HTTP method and path into one, so that
GET
`getNewForm()` combines the definition of HTTP method and path into one, so that
`GET`
requests for `appointments/new` are handled by that method.
The `getForDay()` method shows another usage of `@RequestMapping`: URI templates. (See
...
...
@@ -651,10 +651,66 @@ application shows a multi-action controller using `@RequestMapping`:
}
----
The above example does not specify
GET vs. PUT, POST
, and so forth, because
`@RequestMapping` maps all HTTP methods by default. Use `@RequestMapping(method=GET)`
to narrow the mapping.
The above example does not specify
`GET` vs. `PUT`, `POST`
, and so forth, because
`@RequestMapping` maps all HTTP methods by default. Use `@RequestMapping(method=GET)`
or
`@GetMapping`
to narrow the mapping.
[[mvc-ann-requestmapping-composed]]
==== Composed @RequestMapping Variants
Spring Framework 4.3 introduces the following method-level _composed_ variants of the
`@RequestMapping` annotation that help to simplify mappings for common HTTP methods and
better express the semantics of the annotated handler method. For example, a
`@GetMapping` can be read as a `GET` `@RequestMapping`.
- `@GetMapping`
- `@PostMapping`
- `@PutMapping`
- `@DeleteMapping`
- `@PatchMapping`
The following example shows a modified version of the `AppointmentsController` from the
previous section that has been simplified with _composed_ `@RequestMapping` annotations.
[source,java,indent=0]
[subs="verbatim,quotes"]
----
@Controller
**@RequestMapping("/appointments")**
public class AppointmentsController {
private final AppointmentBook appointmentBook;
@Autowired
public AppointmentsController(AppointmentBook appointmentBook) {
this.appointmentBook = appointmentBook;
}
**@GetMapping**
public Map
<String
,
Appointment
>
get() {
return appointmentBook.getAppointmentsForToday();
}
**@GetMapping("/{day}")**
public Map
<String
,
Appointment
>
getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
return appointmentBook.getAppointmentsForDay(day);
}
**@GetMapping("/new")**
public AppointmentForm getNewForm() {
return new AppointmentForm();
}
**@PostMapping**
public String add(@Valid AppointmentForm appointment, BindingResult result) {
if (result.hasErrors()) {
return "appointments/new";
}
appointmentBook.addAppointment(appointment);
return "redirect:/appointments";
}
}
----
[[mvc-ann-requestmapping-proxying]]
==== @Controller and AOP Proxying
...
...
src/asciidoc/whats-new.adoc
浏览文件 @
c121f460
...
...
@@ -674,6 +674,7 @@ Spring 4.3 also improves the caching abstraction as follows:
* Built-in support for <<mvc-ann-requestmapping-head-options,HTTP HEAD and HTTP OPTIONS>>.
* New `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping`, and `@PatchMapping`
_composed annotations_ for `@RequestMapping`.
** See <<mvc-ann-requestmapping-composed>> for details.
* New `@RequestScope`, `@SessionScope`, and `@ApplicationScope` _composed annotations_ for web scopes.
* New `@RestControllerAdvice` annotation with combined `@ControllerAdvice` with `@ResponseBody` semantics.
* `@ResponseStatus` is now supported at the class level and inherited by all methods.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录