Rest風格簡單使用

2021-07-17 03:31:31 字數 966 閱讀 5552

本文基於已經會使用springmvc,但是未用過rest風格的前提。

未使用rest風格的controller

@controller

public

class

testcontroller

@responsebody

public user testpage(@requestparam(value = "userid") long userid)

}

使用rest風格後的controller

@restcontroller

public

class

testcontroller

public user resttestpage(@pathvariable("userid") long userid)

}

get請求方式的url

未使用rest風格:

使用rest風格後:

css與js引入路徑問題

未使用rest風格時:

rel="stylesheet"

href="css/bootstrap.css"

type="text/css"/>

src="js/jquery-2.1.3.min.js"/>

上面引入css與js檔案的路徑是可以正確引入的。但是使用rest風格後,就不能正常引入了。

使用rest風格時:

rel="stylesheet"

href="/css/bootstrap.css"

type="text/css"/>

src="/js/jquery-2.1.3.min.js"/>

rest風格使用兩個變數 REST風格

path view rest風格 介紹rest 我們這種風格是相當於帶引數時,引數沒有使用傳統的?號後面帶引數形式 我們可以清晰的看出來我們的引數是1 示例 view id 1 view 1 rest 全稱 reqresentational state transfer 即表述性狀態轉移 可以簡單的...

REST架構風格

rest風格通過uri訪問得到的資訊是自我描述的,包括了資訊本身和表示方式 html,xml,資料流等 資訊的描述是採用最通用的協議 http 超文字轉換協議 來進行的.客戶端根據資訊的表示解析和展示資訊本身.而互動是通過http的幾個基本操作 get,put,post,delete 來實現.一些看...

REST設計風格

2000年,roy thomas fielding博士在他的博士 architectural styles and the design of network based software architectures 中提出了幾種軟體應用的架構風格,rest作為其中的一種架構風格在這篇 中進行了概括...