Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
e9ac4bc0
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,发现更多精彩内容 >>
提交
e9ac4bc0
编写于
6月 16, 2009
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved REST HTTP Method Conversion to View chapter.
上级
06777c81
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
45 deletion
+52
-45
spring-framework-reference/src/rest.xml
spring-framework-reference/src/rest.xml
+0
-44
spring-framework-reference/src/view.xml
spring-framework-reference/src/view.xml
+52
-1
未找到文件。
spring-framework-reference/src/rest.xml
浏览文件 @
e9ac4bc0
...
...
@@ -38,50 +38,6 @@
configuration
</link>
to understand the general programming model.
</para>
</section>
<section
id=
"rest-method-conversion"
>
<title>
HTTP Method Conversion
</title>
<para>
A key principle of REST is the use of the Uniform Interface. This
means that all resources (URLs) can be manipulated using the same four
HTTP methods: GET, PUT, POST, and DELETE. For each methods, the HTTP
specification defines the exact semantics. For instance, a GET should
always be a safe operation, meaning that is has no side effects, and a
PUT or DELETE should be idempotent, meaning that you can repeat these
operations over and over again, but the end result should be the same.
While HTTP defines these four methods, HTML only supports two: GET and
POST. Fortunately, there are two possible workarounds: you can either
use JavaScript to do your PUT or DELETE, or simply do a POST with the
'real' method as an additional parameter (modeled as a hidden input
field in an HTML form). This latter trick is what Spring's
<classname>
HiddenHttpMethodFilter
</classname>
does. This filter is a
plain Servlet Filter and therefore it can be used in combination with
any web framework (not just Spring MVC). Simply add this filter to your
web.xml, and a POST with a hidden _method parameter will be converted
into the corresponding HTTP method request.
</para>
<section
id=
"rest-form-tags"
>
<title>
Supporting Spring form tags
</title>
<para>
To support HTTP method conversion the Spring MVC form tag was
updated to support setting the HTTP method. For example, the following
snippet taken from the updated Petclinic sample
</para>
<programlisting
language=
"xml"
>
<
form:form method="delete"
>
<
p class="submit"
><
input type="submit" value="Delete Pet"/
><
/p
>
<
/form:form
>
</programlisting>
<para>
This will actually perform an HTTP POST, with the 'real' DELETE
method hidden behind a request parameter, to be picked up by the
<classname>
HiddenHttpMethodFilter
</classname>
. The corresponding
@Controller method is shown below
</para>
<programlisting
language=
"java"
>
@RequestMapping(method = RequestMethod.DELETE)
public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {
this.clinic.deletePet(petId);
return "redirect:/owners/" + ownerId;
}
</programlisting>
</section>
</section>
<section
id=
"rest-etag"
>
<title>
ETag support
</title>
...
...
spring-framework-reference/src/view.xml
浏览文件 @
e9ac4bc0
...
...
@@ -737,6 +737,57 @@ productList.url=/WEB-INF/jsp/productlist.jsp</programlisting>
<
/tr
>
<
/form
>
</programlisting>
</section>
<section
id=
"rest-method-conversion"
>
<title>
HTTP Method Conversion
</title>
<para>
A key principle of REST is the use of the Uniform Interface.
This means that all resources (URLs) can be manipulated using the same
four HTTP methods: GET, PUT, POST, and DELETE. For each methods, the
HTTP specification defines the exact semantics. For instance, a GET
should always be a safe operation, meaning that is has no side
effects, and a PUT or DELETE should be idempotent, meaning that you
can repeat these operations over and over again, but the end result
should be the same. While HTTP defines these four methods, HTML only
supports two: GET and POST. Fortunately, there are two possible
workarounds: you can either use JavaScript to do your PUT or DELETE,
or simply do a POST with the 'real' method as an additional parameter
(modeled as a hidden input field in an HTML form). This latter trick
is what Spring's
<classname>
HiddenHttpMethodFilter
</classname>
does.
This filter is a plain Servlet Filter and therefore it can be used in
combination with any web framework (not just Spring MVC). Simply add
this filter to your web.xml, and a POST with a hidden _method
parameter will be converted into the corresponding HTTP method
request.
</para>
<para>
To support HTTP method conversion the Spring MVC form tag was
updated to support setting the HTTP method. For example, the following
snippet taken from the updated Petclinic sample
</para>
<programlisting
language=
"xml"
>
<
form:form method="delete"
>
<
p class="submit"
><
input type="submit" value="Delete Pet"/
><
/p
>
<
/form:form
>
</programlisting>
<para>
This will actually perform an HTTP POST, with the 'real' DELETE
method hidden behind a request parameter, to be picked up by the
<classname>
HiddenHttpMethodFilter
</classname>
, as defined in web.xml:
</para>
<programlisting
language=
"java"
>
<
filter
>
<
filter-name
>
httpMethodFilter
<
/filter-name
>
<
filter-class
>
org.springframework.web.filter.HiddenHttpMethodFilter
<
/filter-class
>
<
/filter
>
<
filter-mapping
>
<
filter-name
>
httpMethodFilter
<
/filter-name
>
<
servlet-name
>
petclinic
<
/servlet-name
>
<
/filter-mapping
>
</programlisting><para>
The corresponding @Controller method
is shown below:
</para>
<programlisting
language=
"java"
>
@RequestMapping(method = RequestMethod.DELETE)
public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {
this.clinic.deletePet(petId);
return "redirect:/owners/" + ownerId;
}
</programlisting>
</section>
</section>
</section>
...
...
@@ -2435,7 +2486,7 @@ simpleReport.reportDataKey=myBeanData</programlisting>
</section>
</section>
<section
id=
"
rest-feedview
"
>
<section
id=
"
view-feeds
"
>
<title>
Feed Views
</title>
<para>
Both
<classname>
AbstractAtomFeedView
</classname>
and
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录