用springAOP解決許可權問題

2021-07-31 12:18:26 字數 1307 閱讀 3295

1.service層

public inte***ce personservice

public class personserviceimpl implements personservice 

@privilegeinfo(name="updateperson")

public void updateperson()

}

2.寫乙個註解privilegeinfo 和

註解解析器

annotationparse

@target(elementtype.method)//這註解只作用在方法上面

@retention(retentionpolicy.runtime)//作用的範圍

public @inte***ce privilegeinfo

/**

* 這是乙個註解解析器

* */

public class annotationparse

return methodaccess; }

}

3.寫乙個許可權privilege 只有name屬性

public class privilege 

public void setname(string name)

}

4.寫乙個切面privilegeaspect,切面裡面用list裝著許可權,寫乙個環繞通知isaccessmethod

/**

* 這是乙個切面,作用是檢視使用者是否有許可權執行目標方法

*/public class privilegeaspect

public void setprivileges(listprivileges)

/*** 這是乙個環繞通知

*/public void isaccessmethod(proceedingjoinpoint joinpoint) throws throwable

} if(flag)else

}}

5.spring的配置檔案中配置

<?xml version="1.0" encoding="utf-8"?>  

6.測試單元

@test

public void test()

Spring AOP 中 Pointcut的用法

1.格式 execution modifiers pattern?ret type pattern declaring type pattern?name pattern param pattern throws pattern?括號中各個pattern分別表示 修飾符匹配 modifier pat...

lesson26 用switch語句解決問題

任務一 投票表決器 設計乙個投票表決器,其功能是 輸入y y,列印agree 輸入n n,列印disagree 輸入其他,列印lose 檔名稱 main.c 作 者 袁生 完成日期 2017年10月23日 版 本 號 v1.0 問題描述 設計乙個投票表決器,其功能是 輸入y y,列印agree,輸入...

Linux下配置npm存放路徑,解決許可權問題

1.開啟cmd命令列,檢視當前配置 輸入npmconfig ls 先看一下當前npm的配置環境,由於我已經修改過,所以可以看到修改後的路徑 2.修改路徑 這裡需要修改兩個路徑,module路徑和cache路徑 module對應prefix cache對應cache 首先在別的盤新建兩個目錄 d no...