Spring註解 持續更新

2021-10-19 13:25:53 字數 1545 閱讀 5877

註解作用

引數/例子

@autowired

用來裝配bean,都可以寫在字段上,或者方法上。

預設情況下必須要求依賴物件必須存在,如果要允許null值,可以設定它的required屬性為false,例如:@autowired(required=false)

@aspect

作用是把當前類標識為乙個切面供容器讀取

註解作用

引數/例子

註解作用

引數/例子

註解作用

引數註解

作用引數

註解作用

引數/例子

@controller

標識乙個該類是spring mvc controller處理器,用來建立處理http請求的物件

@configuration

@componentscan

該註解缺省會掃瞄該類所在的包下所有的配置類,相當於之前的 context:component-scan。

@component

spring中的乙個註解,它的作用就是實現bean的注入

註解作用

引數/例子

註解作用

引數/例子

@enableaspectjautoproxy

表示開啟aop**自動配置

設定@enableaspectjautoproxy(exposeproxy=true)表示通過aop框架暴露該**物件,aopcontext能夠訪問,設定@enableaspectjautoproxy(proxytargetclass=true),則代表全部使用cglib**,否則介面為jdk**,其他為cglib**

註解作用

引數註解

作用引數/例子

@modelattribute

註解用於將方法的引數或方法的返回值繫結到指定的模型屬性上,並返回給web檢視

引數註解

作用引數

註解作用

引數/例子

@pathvariable

可以將url中佔位符引數繫結到處理器類的方法形參中@pathvariable(「***「)

@requirespermissions

要求subject中必須同時含有file:read和write:afile.txt的許可權才能執行方法somemethod()

@requirespermissions( )void somemethod();

註解作用

引數註解

作用引數/例子

@restcontroller

spring4之後加入的註解,原來在@controller中返回json需要@responsebody來配合,如果直接用@restcontroller替代@controller就不需要再配置@responsebody,預設返回json格式。

作用引數

@responsebody

與@controller結合使用,表明返回json資料

引數/例子

@responsebody

作用於方法,表明此方法的返回值寫入http response body中

引數/例子

記錄spring註解(持續更新)

0.conditionalo singbean conditionalo singbean conditionalonproperty value pt1 matchifmissing true bean public letter letter 以上配置為configuration配置類內容,含義...

摘錄 關於spring的註解(持續更新中)

關於註解 1.resource 感覺要是new就在 頭上用到 2.scope prototype 域多為非單例 3.component service 多用在service的實現類中 controller 用在action中 repository 多用在dao的實現類中 簡介 1 value met...

spring的註解 後續更新

特定註解包括 可以建立乙個類的例項 例項的變數名為 類名的首字母小寫 component 基本註解,標識了乙個受 spring 管理的元件 respository 標識持久層元件 service 標識服務層 業務層 元件 controller 標識表現層元件 例如package lesson02.c...