spring boot 註解極其知識點

2021-08-27 21:19:25 字數 1303 閱讀 7477

@value  從配置檔案讀取引數 例子  註解@value("$")

@configurationproperties 把yml裡面一組配置引數封裝成乙個類 例子:

@configurationproperties(prefix = "girl")  prefix 對映的是yml裡面的girl
@component 向springboot註冊乙個類  例子:

private girproperties girproperties; 報錯的時候,引入

@component

@autowired 注入乙個類 例子:

private girproperties girproperties;
@restcontroller==@controller +@responsebody  一般用@restcontroller就夠了,這樣不會涉及前端的。更好的前後的分離。

yml配置檔案的使用    yml配置檔案,結構更清晰,語法更嚴謹   屬性配置可以用.properties,也可以用.yml   例子:

server:

port: 8080

girl:

cupsize: b

age: 18

環境切換配置檔案   spring:    

profile:  

active:dev

切換到開發環境,如果是prod切換到生產環境 或者是把工程編譯打包之後,在命令列執行

3 controller獲取引數:

@requestparam 獲取請求引數的值     @pathvariable("id") integer myid,http://localhost:8081/hello/say?id=100

獲取url中的資料http:xx/hello/99

2:  @requestparam,獲取請求引數的值http:project/hh/name=xx           @requestparam(value="id",required = false

(是否為必傳),defaultvalue = "0")

springboot 註解總結

springboot註解知識點歸納 當實現rest ful web services時,response將一直通過response body傳送。controller 用於定義控制器類,在spring 專案中由控制器負責將使用者發來的url請求 到對應的服務介面 service層 restcontr...

Spring boot核心註解

這裡面必須注意的註解是 springbootconfiguration enableautoconfiguration componentscan 二 springbootconfiguration 這個註解其實可以當場configuration 三 enableautoconfiguration ...

springboot註解詳解

標註註解 restcontroller 標示當前類是乙個控制類,是springboot提供的基於restfull風格開發,該註解是乙個組合註解,由 controller和 responsebody構成,如果當前類標示restcontroller,則在返回資料是以json格式返回。postconstr...