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

班级app网站建设在哪个网站可以免费做广告

班级app网站建设,在哪个网站可以免费做广告,迈步者seo,小程序开发平台哪种品牌的好声明: 本文实现SpringMVC基本功能,注释加在代码里面,本文最后有gitee上源码地址 Main public class Main {//类一加载就执行这个静态块static {//当前类所在的路径String path Main.class.getResource("").getPath();//当前类所…

声明:

本文实现SpringMVC基本功能,注释加在代码里面,本文最后有gitee上源码地址

Main

public class Main {//类一加载就执行这个静态块static {//当前类所在的路径String path = Main.class.getResource("").getPath();//当前类所在的包名String packageName = Main.class.getPackage().getName();HeaboyMvc.scanner(path,packageName);}public static void main(String[] args) {HeaboyMvc.exec("","");HeaboyMvc.exec("test","index1");HeaboyMvc.exec("test","");System.out.println("Hello World!");}
}
  • 我们执行程序从这个类开始,类加载的时候,先执行静态块(扫描所有的文件,把类文件的实例和类文件的方法 用HashMap存起来)
  • main方法中的exec是模拟调用接口,第一个参数是类的@RequestMapping的value值,第二个参数是方法的@ReqeustMapping的value值
     

HeaboyMvc

public class HeaboyMvc {//存类的方法private static HashMap<String, Map<String,Method>> map=new HashMap<>();//存类的实例private static HashMap<String, Object> objMap=new HashMap<>();public static void exec(String classPath,String methodPath){if(objMap.get(classPath)==null){System.out.println("没有这个类 404");}else {if(map.get(classPath).get(methodPath)==null){System.out.println("没有这个方法 404");}else {try {map.get(classPath).get(methodPath).invoke(objMap.get(classPath));} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}}}public static void scanner(String path,String packageName){//扫描目录下所有的文件夹//拿到了所有文件的路径List<String> paths = traverseFolder2(path);for (String p : paths) {//拿到文件的名p=p.substring(path.length()-1);try {//用包名和一些替换加上文件名得到全限定名String className=packageName+"."+p.replaceAll( Matcher.quoteReplacement(File.separator),".");String replace = className.replace(".class", "");//拿到类的信息Class<?> cl = ClassLoader.getSystemClassLoader().loadClass(replace);//判断是否为Controllerif(isController(cl)){//判断是否加RequestMappingif(isRequestMapping(cl)){//拿到注解RequestMapping requestMapping = getRequestMapping(cl);//判断注解中的值是否重复if(map.containsKey(requestMapping.value())){throw  new RuntimeException("类多注解值:"+requestMapping.value());}else {//没有重复就把类放两个map进去map.put(requestMapping.value(),new HashMap<>());objMap.put(requestMapping.value(),cl.newInstance());}//拿到类中的方法Method[] declaredMethods = cl.getDeclaredMethods();//遍历类中的方法for (Method declaredMethod : declaredMethods) {if(isRequestMapping(declaredMethod)){RequestMapping mapping = getRequestMapping(declaredMethod);if(map.get(requestMapping.value()).containsKey(mapping.value())){throw  new RuntimeException("方法多注解值:"+requestMapping.value());}else {//把当前的类方法存起来map.get(requestMapping.value()).put(mapping.value(),declaredMethod);}}}}else {throw  new RuntimeException("类无requestMapping");}}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();}}}private static boolean isController(Class cl){Annotation annotation = cl.getAnnotation(Controller.class);if(annotation!=null){return  true;}return false;}private static boolean isRequestMapping(Class cl){Annotation annotation = cl.getAnnotation(RequestMapping.class);if(annotation!=null){return  true;}return false;}private  static boolean isRequestMapping(Method method){Annotation annotation = method.getAnnotation(RequestMapping.class);if(annotation!=null){return  true;}return false;}private static RequestMapping getRequestMapping(Class cl){Annotation annotation = cl.getAnnotation(RequestMapping.class);if(annotation instanceof  RequestMapping){return  (RequestMapping) annotation;}return null;}private static RequestMapping getRequestMapping(Method method){Annotation annotation = method.getAnnotation(RequestMapping.class);if(annotation instanceof  RequestMapping){return  (RequestMapping) annotation;}return null;}private static List<String> traverseFolder2(String path) {//路径转化为文件File file = new File(path);List<String> classFiles=new ArrayList<>();if (file.exists()) {//新建list用来存放文件LinkedList<File> list = new LinkedList<File>();File[] files = file.listFiles();//遍历for (File file2 : files) {//只要是文件夹就添加进listif (file2.isDirectory()) {list.add(file2);} else {//不是文件夹就放到classFiles中classFiles.add(file2.getAbsolutePath());}}File temp_file;//如果文件夹不空,就一直循环找文件while (!list.isEmpty()) {temp_file = list.removeFirst();files = temp_file.listFiles();for (File file2 : files) {if (file2.isDirectory()) {list.add(file2);} else {classFiles.add(file2.getAbsolutePath());}}}} else {}//获得所有文件的路径return classFiles;}
}
  • 先扫包,如果是文件夹就放到list中,如果不是文件夹就是文件就放到classFiles中,判断list是否为空,如果不为空就把存进的文件夹的文件展示出来继续遍历,同时把此文件夹从list中取出,经过几次之后,就可以获得所有得到类文件的路径  
  • 遍历classFiles,拿到包名,对遍历出的类文件的路径进行替换和截取,获得了类的全限定名,判断加没加@Controller注解,再判断加没加@RequestMapping注解,判断@RequeatMapping注解中的value是否重复,如果不重复就把此value存起来,并对此类中的方法进行遍历,如果方法加了@RequestMapping,就用map把方法的value也存起来

注解 

Controller

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @ interface Controller {
}

RequestMapping 

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD})
public @interface RequestMapping {/**** @return*/String value() default "";
}

TestController

@Controller
@RequestMapping("test")
public class TestController {@RequestMappingpublic  String index(){System.out.println("test->index");return "";}@RequestMapping("index1")public  String index1(){System.out.println("test->index1");return "";}
}

http://www.lbrq.cn/news/2352493.html

相关文章:

  • 南京户外广告公司排行榜seo关键词排名软件
  • 建设银行怎么网站定制短信通知关键词推广优化app
  • wordpress 订餐模板seo网络推广
  • 网站搭建公司官网中国搜索引擎大全
  • 成都网站排名优化开发近一周热点新闻
  • 盗用别的公司网站模块找关键词的方法与技巧
  • 衡水市做网站百度账户
  • 定制网站建设网销怎么销售的
  • 培训网站建设机构衡阳网站优化公司
  • 携车网网站开发怎么样怎么自己创建网址
  • 企业网站本身应该就是企业( )的一部分百度快速排名优化技术
  • 网站如何做下一页西安百度网站快速排名
  • 楼盘建设信息网站百度爱采购优化软件
  • 做任务赚q红包的网站培训心得简短
  • 技术共享平台seo推广营销靠谱
  • 备案成功后怎么建设网站seo综合查询站长工具
  • 做网站应该用什么数据库百度热搜大数据
  • excel做网站链接娄底seo
  • 黄浦做网站seo优化是指
  • 公司官网网址陕西seo主管
  • 网站域名后缀网络推广公司口碑
  • 做公司网站需要制作内容营业推广是一种什么样的促销方式
  • 做网站 前途怎么建网址
  • 在人才网站做业务搜狗网站收录提交入口
  • 网站建设的一般流程是seo服务外包
  • 策划书中网站制作怎么写杭州小程序建设公司
  • 做旅游网站犯法吗技术培训
  • 万州区城乡建设委员会网站市场推广怎么做
  • 上海好的高端网站建设服务公司企业网站设计欣赏
  • 丽水做网站公司seo教程自学网
  • 能行为监测算法:低成本下的高效管理
  • 第六章 OBProxy 路由与使用运维
  • 技术分享:如何用规则定义生成自定义文件时间戳
  • 计算机网络:(九)网络层(下)超详细讲解互联网的路由选择协议、IPV6与IP多播
  • day053-初识docker与基础命令
  • 【人工智能99问】神经网络的工作原理是什么?(4/99)