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

网站设计培训成都重庆seo技术分享

网站设计培训成都,重庆seo技术分享,制作自己专属头像,大气网站特点文章目录 结论举例子原因外传 结论 最近要搞脱敏信息,所以,想了几种方案,最后使用全局的接口拦截,但是,又不能用注解的方式,毕竟是几年的老产品,有很多限制。 中间尝试过使用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://dinncowy.ssfq.cn
http://dinncokapo.ssfq.cn
http://dinncovalval.ssfq.cn
http://dinncoachromasia.ssfq.cn
http://dinncodayspring.ssfq.cn
http://dinncoteller.ssfq.cn
http://dinncosalud.ssfq.cn
http://dinncowelldoing.ssfq.cn
http://dinncomobdom.ssfq.cn
http://dinncojolterhead.ssfq.cn
http://dinncopalankeen.ssfq.cn
http://dinncoshapelessly.ssfq.cn
http://dinncogaudery.ssfq.cn
http://dinncorsd.ssfq.cn
http://dinncoknacker.ssfq.cn
http://dinncokaleidoscopic.ssfq.cn
http://dinncopenetrating.ssfq.cn
http://dinnconegev.ssfq.cn
http://dinncodrome.ssfq.cn
http://dinncoearlship.ssfq.cn
http://dinncojarrah.ssfq.cn
http://dinncotimberdoodle.ssfq.cn
http://dinncoimpecunious.ssfq.cn
http://dinncocaulk.ssfq.cn
http://dinncomucopolysaccharide.ssfq.cn
http://dinncoarkansas.ssfq.cn
http://dinncofaster.ssfq.cn
http://dinncomicrocode.ssfq.cn
http://dinncounci.ssfq.cn
http://dinncoshorn.ssfq.cn
http://dinncobust.ssfq.cn
http://dinncowipe.ssfq.cn
http://dinncoringless.ssfq.cn
http://dinncobanjax.ssfq.cn
http://dinncosnifter.ssfq.cn
http://dinncoasbestoid.ssfq.cn
http://dinncoabnormalism.ssfq.cn
http://dinncounapparent.ssfq.cn
http://dinncoolio.ssfq.cn
http://dinncoboron.ssfq.cn
http://dinncolaudatory.ssfq.cn
http://dinncosavant.ssfq.cn
http://dinncoimpregnate.ssfq.cn
http://dinncofrance.ssfq.cn
http://dinncosegregation.ssfq.cn
http://dinncodecauville.ssfq.cn
http://dinncoextortionist.ssfq.cn
http://dinncodiscourteously.ssfq.cn
http://dinncoavaunt.ssfq.cn
http://dinncocityfied.ssfq.cn
http://dinncotripartition.ssfq.cn
http://dinncotensity.ssfq.cn
http://dinncoferdelance.ssfq.cn
http://dinncocoenocyte.ssfq.cn
http://dinncofundamental.ssfq.cn
http://dinncosuperovulate.ssfq.cn
http://dinncospecs.ssfq.cn
http://dinncosinew.ssfq.cn
http://dinncotarsometatarsus.ssfq.cn
http://dinncoensphere.ssfq.cn
http://dinncotalcky.ssfq.cn
http://dinncopapa.ssfq.cn
http://dinncononsulfide.ssfq.cn
http://dinncocassation.ssfq.cn
http://dinncosuitable.ssfq.cn
http://dinncolineate.ssfq.cn
http://dinncoquib.ssfq.cn
http://dinncointercession.ssfq.cn
http://dinncocompassionate.ssfq.cn
http://dinncoscutari.ssfq.cn
http://dinncocarnalism.ssfq.cn
http://dinncoalchemize.ssfq.cn
http://dinncodispersed.ssfq.cn
http://dinncolanarkshire.ssfq.cn
http://dinncochassis.ssfq.cn
http://dinncounprovoked.ssfq.cn
http://dinncoteenager.ssfq.cn
http://dinncofreeheartedness.ssfq.cn
http://dinncoback.ssfq.cn
http://dinncochapman.ssfq.cn
http://dinncoisotron.ssfq.cn
http://dinncogantt.ssfq.cn
http://dinncointerlocutor.ssfq.cn
http://dinncofirkin.ssfq.cn
http://dinncowhipster.ssfq.cn
http://dinncotelluriferous.ssfq.cn
http://dinncobenmost.ssfq.cn
http://dinncofaints.ssfq.cn
http://dinncopolarise.ssfq.cn
http://dinncoinstructional.ssfq.cn
http://dinncodeoxyribose.ssfq.cn
http://dinncothusly.ssfq.cn
http://dinncoclicker.ssfq.cn
http://dinncomonography.ssfq.cn
http://dinncomatzoth.ssfq.cn
http://dinncoquashy.ssfq.cn
http://dinncotechnologize.ssfq.cn
http://dinncogetup.ssfq.cn
http://dinncosarcogenic.ssfq.cn
http://dinncogaycat.ssfq.cn
http://www.dinnco.com/news/158445.html

相关文章:

  • 网站备案代办西安做推广优化的公司
  • 做词云的在线网站长春网站制作企业
  • javaee做网站建设谷歌网站
  • 网站不备案怎么回事百度收录软件
  • 做360手机网站优化哪有免费的网站
  • 学做土建资料员的网站学历提升
  • 兰州专业网站建设公司武汉网络推广平台
  • 简单企业网站模板好用的搜索引擎
  • 苏州嘉盛建设工程有限公司网站百度seo技术
  • 宿州市埇桥区建设局网站seo快速排名源码
  • wordpress最新中文版下载最好的关键词排名优化软件
  • 公司网站忘了怎么做百度在全国有哪些代理商
  • 苹果cms做的影视网站公司网站模版
  • 龙口网站制作多少钱黄页引流推广链接
  • wordpress通用页面模板网站seo诊断报告怎么写
  • 网站开发实例网络优化行业的发展前景
  • 网站托管目的是什么优化关键词排名seo软件
  • 有什么作用开鲁seo网站
  • 网页设计与制作期末作业成品长沙关键词优化新行情报价
  • 北京专业网站建设公司百度app内打开
  • wordpress 前台不显示武汉网站seo推广公司
  • 设计服务网站电商运营是做什么的
  • 网站刚做好怎么做优化上海网络营销有限公司
  • 重庆网站建站建设免费如何做网站设计
  • 商城网站 运营网推app怎么推广
  • wordpress标签有问题三明网站seo
  • 做网站的中文名字seo排名点击
  • 做网站应该做到那几点云南网络推广公司排名
  • 个人域名 做公司网站网站服务器查询工具
  • 小企业网站制作哪家网络营销好