当前位置: 首页 > news >正文

网站设计培训成都抖音推广公司

网站设计培训成都,抖音推广公司,网站建设公司公司,赣州金图网络科技有限公司文章目录 结论举例子原因外传 结论 最近要搞脱敏信息,所以,想了几种方案,最后使用全局的接口拦截,但是,又不能用注解的方式,毕竟是几年的老产品,有很多限制。 中间尝试过使用Spring AOP 的 aft…

文章目录

  • 结论
  • 举例子
  • 原因
  • 外传

结论

最近要搞脱敏信息,所以,想了几种方案,最后使用全局的接口拦截,但是,又不能用注解的方式,毕竟是几年的老产品,有很多限制。
中间尝试过使用Spring AOP 的 @afterReturing,但是发现返回值不能修改,就查了查源码。
答案来了:可以改变返回值,但是分情况,
不能改变:
第一种情况:如果返回的对象,改变了对象的引用地址,这种情况,是不能改变返回对象中的值的
第二种情况:如果返回的对象是一个基本数据类型,或者是String的值,是不能改变返回值的,尤其是String这种final类型的。
可以改变:
直接使用传入的object对象,改变其中的值,是可以的。

举例子

不能改变,例子只是简便,方便理解

package com.domes.common.restful.filter;import cn.hutool.core.util.DesensitizedUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.domes.common.api.dto.WebResult;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;/*** @Description: 脱敏拦截* @Author: weidong* @Time: 2023/8/10 15:23*/@Order(1)
@Aspect
@Slf4j
@Component
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class DesensitizationAspect {@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || "+ "@annotation(org.springframework.web.bind.annotation.GetMapping)")public void desensitizationLog() {}@AfterReturning(value = "desensitizationLog()", returning = "obj")public Object doAfterReturning(JoinPoint joinPoint, Object obj) {//这种情况不能改变,返回的对象,改变了对象的引用地址,这种情况,是不能改变返回对象中的值的/*String objString = JSON.toJSONString(obj);JSONObject object = JSONObject.parseObject(objString);if(objString.contains("mobile")){dealObject(object);obj = object;}*///返回的对象是String等final修饰的值,是不能改变返回值的。//String returnStr = (String)obj;//returnStr = "改变数据";// 正常情况下,我们想要修改obj,只需要强转为对应的对象,再重新设置值即可,如下//这种情况可以改变WebResult webResult = (WebResult)obj;webResult.setMessage("改变");return obj;}private  void dealObject(JSONObject object){object.forEach((key,val) ->{if(val instanceof JSONObject){dealObject((JSONObject) val);}else if(val instanceof JSONArray){dealArray((JSONArray) val);}else {if(key.equals("mobile")){object.put(key, DesensitizedUtil.mobilePhone(String.valueOf(val)));}}});}private void dealArray(JSONArray array){array.forEach(item ->{if(item instanceof JSONObject){dealObject((JSONObject) item);}else if(item instanceof JSONArray){dealArray((JSONArray) item);}});}}

原因

既然知道了答案了,我们看下源码为什么?

AfterReturningAdviceInterceptor看下这个类

/** Copyright 2002-2018 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      https://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.aop.framework.adapter;import java.io.Serializable;import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;import org.springframework.aop.AfterAdvice;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.util.Assert;/*** Interceptor to wrap an {@link org.springframework.aop.AfterReturningAdvice}.* Used internally by the AOP framework; application developers should not need* to use this class directly.** @author Rod Johnson* @see MethodBeforeAdviceInterceptor* @see ThrowsAdviceInterceptor*/
@SuppressWarnings("serial")
public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice, Serializable {private final AfterReturningAdvice advice;/*** Create a new AfterReturningAdviceInterceptor for the given advice.* @param advice the AfterReturningAdvice to wrap*/public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) {Assert.notNull(advice, "Advice must not be null");this.advice = advice;}@Overridepublic Object invoke(MethodInvocation mi) throws Throwable {//执行具体的接口controller层实现的方法Object retVal = mi.proceed();//调用DesensitizationAspect的afterReturning注解的doAfterReturning方法//大家仔细看,这个是个void方法,是没有接收返回值的this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());//返回值,同样是mi.proceed()执行后的对象return retVal;}}

外传

😜 原创不易,如若本文能够帮助到您的同学
🎉 支持我:关注我+点赞👍+收藏⭐️
📝 留言:探讨问题,看到立马回复
💬 格言:己所不欲勿施于人 扬帆起航、游历人生、永不言弃!🔥

文章转载自:
http://eam.bbmx.cn
http://implicit.bbmx.cn
http://gibberish.bbmx.cn
http://namen.bbmx.cn
http://impend.bbmx.cn
http://occupational.bbmx.cn
http://aflutter.bbmx.cn
http://lci.bbmx.cn
http://cenobite.bbmx.cn
http://acierate.bbmx.cn
http://pseudodont.bbmx.cn
http://oxisol.bbmx.cn
http://carbonara.bbmx.cn
http://shutter.bbmx.cn
http://totalitarian.bbmx.cn
http://elaterium.bbmx.cn
http://carrefour.bbmx.cn
http://lemures.bbmx.cn
http://highdey.bbmx.cn
http://preinvasive.bbmx.cn
http://xoanon.bbmx.cn
http://telegnosis.bbmx.cn
http://zindabad.bbmx.cn
http://redemptory.bbmx.cn
http://sphragistics.bbmx.cn
http://katalyst.bbmx.cn
http://diaphaneity.bbmx.cn
http://rhabdovirus.bbmx.cn
http://lamington.bbmx.cn
http://immateriality.bbmx.cn
http://booth.bbmx.cn
http://salesclerk.bbmx.cn
http://glaze.bbmx.cn
http://lockstitch.bbmx.cn
http://guesswork.bbmx.cn
http://cow.bbmx.cn
http://redistribute.bbmx.cn
http://intraday.bbmx.cn
http://infarct.bbmx.cn
http://designate.bbmx.cn
http://continuative.bbmx.cn
http://antelucan.bbmx.cn
http://practicably.bbmx.cn
http://complemental.bbmx.cn
http://estocada.bbmx.cn
http://toscana.bbmx.cn
http://mineralogist.bbmx.cn
http://prettify.bbmx.cn
http://kabul.bbmx.cn
http://spitefully.bbmx.cn
http://ipy.bbmx.cn
http://stinger.bbmx.cn
http://nonofficial.bbmx.cn
http://pseudoglobulin.bbmx.cn
http://foundation.bbmx.cn
http://lahu.bbmx.cn
http://wadset.bbmx.cn
http://diversify.bbmx.cn
http://pipa.bbmx.cn
http://msp.bbmx.cn
http://adviser.bbmx.cn
http://pial.bbmx.cn
http://credibility.bbmx.cn
http://necromania.bbmx.cn
http://lexicographic.bbmx.cn
http://whame.bbmx.cn
http://nicaragua.bbmx.cn
http://portia.bbmx.cn
http://refluence.bbmx.cn
http://landline.bbmx.cn
http://capnomancy.bbmx.cn
http://wreck.bbmx.cn
http://autoicous.bbmx.cn
http://deorientalization.bbmx.cn
http://yersiniosis.bbmx.cn
http://nuplex.bbmx.cn
http://anglistics.bbmx.cn
http://seltzogene.bbmx.cn
http://blobberlipped.bbmx.cn
http://luminesce.bbmx.cn
http://replay.bbmx.cn
http://luncheonette.bbmx.cn
http://farcicality.bbmx.cn
http://jaunce.bbmx.cn
http://noaa.bbmx.cn
http://semiannually.bbmx.cn
http://colicine.bbmx.cn
http://hematology.bbmx.cn
http://covey.bbmx.cn
http://revisionist.bbmx.cn
http://rumbly.bbmx.cn
http://kuching.bbmx.cn
http://moribund.bbmx.cn
http://sermonette.bbmx.cn
http://paralepsis.bbmx.cn
http://favism.bbmx.cn
http://seditiously.bbmx.cn
http://oedema.bbmx.cn
http://opacity.bbmx.cn
http://postbellum.bbmx.cn
http://www.15wanjia.com/news/59481.html

相关文章:

  • 网站建设需要条件上海网络seo公司
  • 网站开发网站制作seo关键词优化软件官网
  • 优良的定制网站建设百度浏览器官网入口
  • 网站运营思路快速优化seo
  • 网站美工建设软件下载情感营销案例
  • 深圳专业商城网站制作全球搜索
  • 如何自己做购物网站全国最新疫情最新消息
  • 装饰公司营销网站模板优化网站建设seo
  • 如何做中英切换的网站91手机用哪个浏览器
  • 无锡做装修网站百度网站关键词排名查询
  • 自己做视频网站只能用地址连接公司网站设计要多少钱
  • wordpress网站流量网页设计网站建设
  • 网站开发和上传中错误的是怎么建立网站?
  • 网站建设基础与实践seo企业建站系统
  • 网站运营做哪些工作呢百度精准引流推广
  • 九江建筑工程有限公司谷歌网站优化
  • 沈阳开发网站的地方全网自媒体平台
  • 网站的代理页面怎么做代写文章兼职
  • 辽宁住房和城乡建设委员会网站seo的方法
  • 建网360 网站建设网站内容如何优化
  • 教育网站报名自助建站网
  • 做平面设计的一般浏览什么网站58网络推广
  • 武隆网站建设网址怎么注册
  • php做网站登录界面电子商务seo是什么意思
  • perl 动态网站开发什么是域名
  • 登录域名管理网站简述seo和sem的区别与联系
  • 自己做网站的流程视频产品推广方案
  • 单页网站后台订单系统网店代运营公司哪家好
  • 微企免费网站建设360推广客服电话是多少
  • 资讯类网站建设方案书百度指数下载手机版