亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

如何利用SpringAOP的返回通知處理數(shù)據(jù)加密返回

 更新時(shí)間:2024年12月20日 09:17:36   作者:淺度差文  
這篇文章主要介紹了如何利用SpringAOP的返回通知處理數(shù)據(jù)加密返回,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧

項(xiàng)目安全要求把所有返回值做加密處理,利用SpringAOP的返回切面可以簡(jiǎn)單方便的做到該需求。

@Aspect
public class ResponseDataEncryptAspect {
    private ObjectMapper objectMapper;
    public ResponseDataEncryptAspect () {
        this.objectMapper = new ObjectMapper();
        // 保持空值也被序列化
        objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    }
	// 攔截Controller內(nèi)帶@RequestMapper的方法及衍生注解即可
    @AfterReturning(value = PointCut.CONTROLLER_POINT_CUT, returning = "res")
    public void jsonDateEncrypt(JoinPoint joinPoint, Object res){
        // 只處理JsonResult返回值
        if (res instanceof JsonResult) {
            JsonResult jsonResult = (JsonResult) res;
            Object data = jsonResult.getData();
            if (null != data) {
                // 把data轉(zhuǎn)成json串,再把json串加密,再替換原來的data,vue攔截到data作全局解密,不影響已綁定的功能。
                String json = objectMapper.writeValueAsString(data);
                String cryptResult = ZYCryptUtils.encryptAES(json);
                // 在全局響應(yīng)結(jié)果里添加一個(gè)布爾值,方便前端判斷到底是密文還是明文
                jsonResult.setEncrypt(true);
                jsonResult.setData(cryptResult);
            }
        }
    }
}

實(shí)際效果:

到此這篇關(guān)于利用SpringAOP的返回通知處理數(shù)據(jù)加密返回的文章就介紹到這了,更多相關(guān)SpringAOP數(shù)據(jù)加密返回內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論