springMVC之Rest風格的URL

2021-09-12 07:57:10 字數 2270 閱讀 999

rest風格的url

以crud為例

新增:/order/ post

修改:/order/1 put 非rest風格的url為 update?id=1

獲取:/order/1 get 非rest風格的url為 get?id=1

刪除:/order/1 delete 非rest風格的url為 delete?id=1

如何傳送put請求和delete請求:

1、需要配置hiddenhttpmethodfilter

2、需要傳送post請求

3、需要在傳送post請求時帶乙個name="_method"的隱藏域,值為delete或put

在springmvc的目標方法中得到id:

使用@pathvariable

**示例

("/springmvc")

@controller

publicclassspringmvctest "

,method=requestmethod.put

)

publicstring restputtest(

@pathvariable

("id"

) integer id)

@responsebody

(value=

"/restdeletetest/"

,method=requestmethod.delete

)

publicstring restdeletetest(

@pathvariable

("id"

) integer id)

(value=

"/restposttest"

,method=requestmethod.post

)

publicstring restposttest()

(value=

"/restgettest/"

,method=requestmethod.get

)

publicstring restgettest(

@pathvariable

integer id)

}jsp**

<

form

action

="springmvc/restputtest/1"

method

="post"

>

<

input

type

="hidden"

name

="_method"

value

="put"

>

<

input

type

="submit"

value

="resttest put"

>

form

>

<

form

action

="springmvc/restdeletetest/1"

method

="post"

>

<

input

type

="hidden"

name

="_method"

value

="delete"

>

<

input

type

="submit"

value

="resttest delete"

>

form

>

<

form

action

="springmvc/restposttest"

method

="post"

>

<

input

type

="submit"

value

="resttest post"

>

form

>

<

ahref

="springmvc/restgettest/1"

>

resttest get

a>

REST風絡的XCAP協議

1 xcap 協議的簡介 xcap xml configuration access protocol xml 配置訪問協議 也稱 xml配置接入協議。它是 ietf 制定的乙個協議,前面陸續發布了一系列草案,於 2007年5 月正式成為 rfc規範 rfc 4825 該協議允許客戶端讀 寫 修改存...

spring MVC 配置rest風格URL

最近公司要用spring mvc,所以上網學習了一下,發現很不錯,這裡說說怎麼配置res風格的url 如 http localhost 8080 test user login 新增spring org.springframework.web.servlet.dispatcherservlet co...

springmvc使用rest風格的404錯誤

當使用rest風格出現404錯誤時,blogservlet name org.springframework.web.servlet.dispatcherservletservlet class contextconfiglocationparam name classpath config mvc...