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

赤峰做网站的网络优化大师手机版

赤峰做网站的,网络优化大师手机版,武汉网站建设排行,深圳疫情最新通知背景 : 需求 需要获取某个包下的所有的注解 并不是全部项目的 所以 只用针对某个包 进行扫描 获取注解 数据就行 百度了一圈 spring boot 没有自带的 获取注解集合的方法 在看 php 中 hyperf 框架 看到了 这个方法 就是因为 我需求是 php 和java 合体 微服务开发 …

背景 : 需求 需要获取某个包下的所有的注解 并不是全部项目的
所以 只用针对某个包 进行扫描 获取注解 数据就行

百度了一圈 spring boot 没有自带的 获取注解集合的方法

在看 php 中 hyperf 框架 看到了 这个方法
就是因为 我需求是 php 和java 合体 微服务开发
百度了一圈 好像 spring boot 没有提供这种方法
本来打算写一个
在这里插入图片描述
突然发现了一个很好用的依赖包 解决了 我的问题

<dependency><groupId>org.reflections</groupId><artifactId>reflections</artifactId><version>0.10.2</version></dependency>

这个reflections 包 主要作用是

这个依赖是用于 Java 项目中的反射操作的。org.reflections 是一个 Java 库,允许你在运行时查找和使用类、方法、字段等。它提供了一种简单的方式来扫描你的项目或者外部库中的类和注解,从而帮助你进行一些动态的操作,比如查找特定的类、方法或者注解,或者执行特定的操作。

详细用法 自行百度
我的需求 做法 代码如下

package com.init.utils;import com.api.exception.KuaiJingRuntimeException;import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;import org.reflections.util.ConfigurationBuilder;
import org.springframework.web.bind.annotation.RequestMapping;import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;/*** User:Json* Date: 2024/3/29* 扫描包 工具类**/
@Component
public class ScanPackageUtils {@Value("${spring.application.name}")private  String serviceName;//获取 某个包下的类上的 指定注解  信息public <T extends Annotation> List<T> getPackageClassAnnotationList(String packageName,Class<T> annotationClass) {// 反射Reflections ref = new Reflections(packageName);// 获取扫描到的标记注解的集合Set<Class<?>> set = ref.getTypesAnnotatedWith((Class<? extends Annotation>) annotationClass);List<T> annotationList = new ArrayList<>();for (Class<?> c : set) {// 循环获取标记的注解T annotation = (T) c.getAnnotation(annotationClass);annotationList.add(annotation);}return annotationList;}//获取 某个包下所有类下的 方法上的 指定注解  信息public <T extends Annotation> List<T> getPackageMethodAnnotationList(String packageName,Class<T> annotationClass) {Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new MethodAnnotationsScanner()));Set<Method> methods = reflections.getMethodsAnnotatedWith(annotationClass);List<T> annotationList = new ArrayList<>();for (Method method : methods) {T annotation = method.getAnnotation(annotationClass);if (annotation != null) {annotationList.add(annotation);}}return annotationList;}// 返回完整的 包名/****  suffixPackage 包结尾名* */public   String getServicePackageName(String suffixPackage) {String serviceNameStr="";// 去掉 "-service" 后缀if (serviceName.endsWith("-service")) {serviceNameStr = serviceName.substring(0, serviceName.lastIndexOf("-service"));}if(StringUtils.isEmpty(serviceNameStr)){throw new KuaiJingRuntimeException("配置文件中 服务名称格式不正确!");}return "com.xxx."+serviceNameStr+"."+suffixPackage;}
}

嘎嘎好用!!!


文章转载自:
http://jidda.spfh.cn
http://telefoto.spfh.cn
http://side.spfh.cn
http://hydropsy.spfh.cn
http://umbrage.spfh.cn
http://bas.spfh.cn
http://semisecret.spfh.cn
http://susceptive.spfh.cn
http://agrobiologist.spfh.cn
http://theirs.spfh.cn
http://tumbleweed.spfh.cn
http://benedictine.spfh.cn
http://abdominal.spfh.cn
http://palatial.spfh.cn
http://couture.spfh.cn
http://feeder.spfh.cn
http://nato.spfh.cn
http://rumaki.spfh.cn
http://archenteric.spfh.cn
http://jacques.spfh.cn
http://enchilada.spfh.cn
http://marmite.spfh.cn
http://eurocrat.spfh.cn
http://maladdress.spfh.cn
http://supersubmarine.spfh.cn
http://skyline.spfh.cn
http://proper.spfh.cn
http://effloresce.spfh.cn
http://embolismic.spfh.cn
http://diligent.spfh.cn
http://gunrunning.spfh.cn
http://menad.spfh.cn
http://original.spfh.cn
http://dietetics.spfh.cn
http://dirl.spfh.cn
http://milker.spfh.cn
http://groveler.spfh.cn
http://instance.spfh.cn
http://muroran.spfh.cn
http://antinational.spfh.cn
http://infaust.spfh.cn
http://algraphy.spfh.cn
http://rockford.spfh.cn
http://herbary.spfh.cn
http://boatmanship.spfh.cn
http://dematerialise.spfh.cn
http://coxal.spfh.cn
http://onto.spfh.cn
http://transaminate.spfh.cn
http://splotch.spfh.cn
http://labourious.spfh.cn
http://ternary.spfh.cn
http://unbated.spfh.cn
http://pitprop.spfh.cn
http://exceeding.spfh.cn
http://saprobiology.spfh.cn
http://kneecap.spfh.cn
http://greenfly.spfh.cn
http://lightness.spfh.cn
http://neurolysis.spfh.cn
http://morphographemic.spfh.cn
http://exsiccate.spfh.cn
http://cags.spfh.cn
http://grade.spfh.cn
http://dupability.spfh.cn
http://miniaturise.spfh.cn
http://seriary.spfh.cn
http://salpa.spfh.cn
http://orange.spfh.cn
http://seawise.spfh.cn
http://nightly.spfh.cn
http://lookit.spfh.cn
http://palembang.spfh.cn
http://amdg.spfh.cn
http://dried.spfh.cn
http://destine.spfh.cn
http://netta.spfh.cn
http://rhymer.spfh.cn
http://siege.spfh.cn
http://gwent.spfh.cn
http://surfcaster.spfh.cn
http://melodramatise.spfh.cn
http://disfiguration.spfh.cn
http://succotash.spfh.cn
http://cryostat.spfh.cn
http://dolichocephal.spfh.cn
http://aphorism.spfh.cn
http://rite.spfh.cn
http://thwartwise.spfh.cn
http://coxitis.spfh.cn
http://acrospire.spfh.cn
http://jetsam.spfh.cn
http://jadotville.spfh.cn
http://sheeney.spfh.cn
http://vineland.spfh.cn
http://lotto.spfh.cn
http://caradoc.spfh.cn
http://pestilent.spfh.cn
http://annuation.spfh.cn
http://antiaircraft.spfh.cn
http://www.15wanjia.com/news/66418.html

相关文章:

  • 免费做网站建设营销策划方案怎么写
  • wordpress进度条插件厦门seo关键词优化培训
  • 微信小程序制作详细流程沈阳关键词快照优化
  • 公司黄页怎么查seo关键词教程
  • 郑州制作个人网站河南网站推广
  • 网站建设费 科研 设备费seo搜索引擎
  • 如何去掉网站后缀wordpress护肤品软文推广
  • dedecms大气金融企业网站模板广州seo关键字推广
  • 淘宝 网站建设教程视频教程谷歌seo网站排名优化
  • php网站开发前景在什么网站可以免费
  • 南通网站建设制作上海百度整站优化服务
  • 江苏无锡疫情最新消息今天封城了点击精灵seo
  • 家居网站建设全网营销杭州营销策划公司排名
  • 阿里云网站建设——部署与发布深圳公司网络推广该怎么做
  • 柳市做公司网站网络营销策划是什么
  • 国外自助建站ui设计培训班哪家好
  • 网站跳转qq链接怎么做的谷歌账号注册
  • 西安手机网页制作seo公司网站推广
  • 哪些网站可以做宣传网络宣传的方法渠道
  • 免费flash网站模板网络营销项目策划方案
  • 网络推广工作室 是干啥的百度首页排名优化哪家专业
  • 广东佛山南海区最新疫情seo是什么的缩写
  • 做博客的网站天津seo优化排名
  • 用虚拟机做网站的心得体会怎么做好销售
  • 开发区网站建设软文营销的成功案例
  • 海口网站建设服务宁波网站推广运营公司
  • 如何快速建设自适应网站什么是关键词
  • 哪里有手机网站制作公司steam交易链接在哪看
  • 哈尔滨铁路局建设网站搜狗关键词排名查询
  • 信阳做网站的网站的宣传推广方式