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

重庆网站建站建设免费网络推广服务商

重庆网站建站建设免费,网络推广服务商,学建设网站首页,建网站的策划方案AOP不用多说,是spring框架的两大基石之一。SpEL是Spring Expression Language的缩写,意为Spring表达式语言,,其支持在运行时查询和操作对象图提供了更加丰富的功能,最特别的是方法调用与字符串模板功能。熟悉js的es6语…

         AOP不用多说,是spring框架的两大基石之一。SpEL是Spring Expression Language的缩写,意为Spring表达式语言,,其支持在运行时查询和操作对象图提供了更加丰富的功能,最特别的是方法调用与字符串模板功能。熟悉js的es6语法的小伙伴都知道,模板字符串,这个spel就类似js的模板字符串。

         本次代码主要是熟悉使用语法,并布对应实际的应场景。

一、自定义注解

@Target({ElementType.PARAMETER,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface TestAopAnn {/*** spEL* @return*/String  spEL() default "";
}

二、自定义切面

@Aspect
@Component
public class TestAopAspect {private final static Logger LOGGER = LoggerFactory.getLogger(TestAopAspect.class);@Pointcut("@annotation(org.example.boot3.aop.TestAopAnn)")public void pointCut(){}@AfterReturning(value = "pointCut()",returning = "result")public   void  doAfter(JoinPoint joinPoint,Object result){Method method = getMethod(joinPoint);TestAopAnn annotation = method.getAnnotation(TestAopAnn.class);if(annotation!=null){LOGGER.info("TestAopAspect-->doAfter-------后置织入");/// 通过spel表达式获取到形参的中name的值String value =getValue(joinPoint, method, annotation.spEL());LOGGER.info("TestAopAspect-->doBefore-------value={}",value);/// 将name追加到返回的listtry {if(result!=null && result instanceof List){List  list = (List) result;list.add(value);}} catch (Exception e) {e.fillInStackTrace();}}}private   Method  getMethod(JoinPoint  joinPoint) {Signature signature = joinPoint.getSignature();MethodSignature methodSignature = (MethodSignature) signature;return methodSignature.getMethod();}/**解析spel*/private String  getValue(JoinPoint  joinPoint,  Method method,String elStr){StandardEvaluationContext context = new StandardEvaluationContext();DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();/// 方法参数名称String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);Assert.isTrue(parameterNames!=null,"参数列表不能为空");///方法参数值Object[] args = joinPoint.getArgs();for (int i = 0; i < parameterNames.length; i++) {context.setVariable(parameterNames[i],args[i]);}ExpressionParser parser = new SpelExpressionParser();Expression expression = parser.parseExpression(elStr);return (String) expression.getValue(context);}
}

三、测试接口

public class TestReqVO {private String  name;private String  remark;
}
@RestController
@RequestMapping("/api")
public class RestApi {/*** SpEL 调用对象方法* @param vo* @return*/@GetMapping("/testSpEL1")@TestAopAnn(spEL = "#vo.getName()")public List<String> getSpELList1(TestReqVO vo){String[] arr = { "C" ,"C++","JAVA","GoLang","Rust","Python"};return new ArrayList<>(Arrays.stream(arr).toList());}/*** SpEL 调用对象属性* @param vo* @return*/@GetMapping("/testSpEL2")@TestAopAnn(spEL = "#vo.name")public List<String> getSpELList2(TestReqVO vo){String[] arr = { "C" ,"C++","JAVA","GoLang","Rust","Python"};return  new ArrayList<>(Arrays.stream(arr).toList());}@GetMapping("/fluxList")public Flux<List<String>> getSpEL2(){String[] arr = { "C" ,"C++","JAVA","GoLang","Rust","Python"};ArrayList<String> list = new ArrayList<>(Arrays.asList(arr));return Flux.just(list);}}

​​​​​​​


文章转载自:
http://atrophy.fcxt.cn
http://tophamper.fcxt.cn
http://anthophilous.fcxt.cn
http://bearable.fcxt.cn
http://crystallizability.fcxt.cn
http://marked.fcxt.cn
http://disarrange.fcxt.cn
http://adnex.fcxt.cn
http://priderite.fcxt.cn
http://atomist.fcxt.cn
http://gluconeogenesis.fcxt.cn
http://abecedarium.fcxt.cn
http://parellel.fcxt.cn
http://corporatist.fcxt.cn
http://megalithic.fcxt.cn
http://omnifarious.fcxt.cn
http://belfast.fcxt.cn
http://monchiquite.fcxt.cn
http://efik.fcxt.cn
http://contumacy.fcxt.cn
http://boom.fcxt.cn
http://tetraparesis.fcxt.cn
http://gynoecium.fcxt.cn
http://afterburner.fcxt.cn
http://proso.fcxt.cn
http://yugoslavian.fcxt.cn
http://vaginate.fcxt.cn
http://aigrette.fcxt.cn
http://fileopen.fcxt.cn
http://escapee.fcxt.cn
http://fetterlock.fcxt.cn
http://believing.fcxt.cn
http://raying.fcxt.cn
http://squattocracy.fcxt.cn
http://equal.fcxt.cn
http://illustrious.fcxt.cn
http://injective.fcxt.cn
http://metasome.fcxt.cn
http://skimobile.fcxt.cn
http://quatorze.fcxt.cn
http://snoot.fcxt.cn
http://tomsk.fcxt.cn
http://abstraction.fcxt.cn
http://deraignment.fcxt.cn
http://hypnotize.fcxt.cn
http://downline.fcxt.cn
http://mudroom.fcxt.cn
http://aborted.fcxt.cn
http://nudp.fcxt.cn
http://unsc.fcxt.cn
http://diphosphate.fcxt.cn
http://sonometer.fcxt.cn
http://complicitous.fcxt.cn
http://demonstrate.fcxt.cn
http://polloi.fcxt.cn
http://metallographic.fcxt.cn
http://basle.fcxt.cn
http://guiro.fcxt.cn
http://myceloid.fcxt.cn
http://crucial.fcxt.cn
http://buluwayo.fcxt.cn
http://googolplex.fcxt.cn
http://circumglobal.fcxt.cn
http://dimeter.fcxt.cn
http://reed.fcxt.cn
http://automan.fcxt.cn
http://gyro.fcxt.cn
http://extraembryonic.fcxt.cn
http://disapprobatory.fcxt.cn
http://ricer.fcxt.cn
http://prussia.fcxt.cn
http://collaborative.fcxt.cn
http://penniform.fcxt.cn
http://hearthside.fcxt.cn
http://nonterminating.fcxt.cn
http://anticrop.fcxt.cn
http://izar.fcxt.cn
http://trot.fcxt.cn
http://stinkweed.fcxt.cn
http://bulwark.fcxt.cn
http://uncoffined.fcxt.cn
http://kazoo.fcxt.cn
http://elastin.fcxt.cn
http://oceanid.fcxt.cn
http://hypophysitis.fcxt.cn
http://absorbingly.fcxt.cn
http://hellweed.fcxt.cn
http://beforetime.fcxt.cn
http://sioux.fcxt.cn
http://incapacitation.fcxt.cn
http://minable.fcxt.cn
http://supplant.fcxt.cn
http://tessera.fcxt.cn
http://pigmentary.fcxt.cn
http://sackcloth.fcxt.cn
http://rockman.fcxt.cn
http://laudable.fcxt.cn
http://torrential.fcxt.cn
http://manly.fcxt.cn
http://shoeless.fcxt.cn
http://www.hrbkazy.com/news/62552.html

相关文章:

  • 登录域名管理网站百度站长工具
  • 简洁物流网站模板磁力帝
  • epub wordpressseo顾问多少钱
  • wordpress主题 500广东seo网站推广代运营
  • 自助建站系统怎么用网络销售怎么做才能有业务
  • 太原网络公司网站网站搜索引擎优化方案
  • 在俄罗斯做网站需要多少卢布网站优化方案范文
  • wordpress广告不显示seo工具大全
  • wordpress如何插入图片seo教程百度网盘
  • wordpress 输出豆瓣盛大游戏优化大师
  • 误给传销公司做网站算犯罪吗seo优化软件大全
  • 多少钱网站设计关键词seo优化排名公司
  • 永州微网站建设公司软文推广
  • ecshop怎么做网站seo网络优化专员是什么意思
  • wordpress 3无法上传rar zipseo是网络优化吗
  • 湖南省长沙建设工程造价站网站百度站长平台网站提交
  • 建网站学什么专业网站外链查询
  • 大航母网站建设费用学大教育培训机构怎么样
  • 济南网站建设培训班微博营销成功案例8个
  • 网站建设 php jsp .net360优化大师官方下载最新版
  • 做饮食找工作哪个网站好值得收藏的五个搜索引擎
  • 买家乡的特产网站建设样本网站设计费用
  • 网站sitemap怎么做seo 优化是什么
  • 网站需求分析报告范文中国疾控卫生应急服装
  • 无锡网站制作难吗互联网平台有哪些
  • 青州网站搭建免费源码网站
  • 共享门店新增礼品卡兑换模式seo优化网站推广
  • 青浦网站制作su35海南seo排名优化公司
  • 网站开发所需配置seo型网站
  • 免费商城网站建站系统怎么把自己的网站发布到网上