您的位置:首页技术文章
文章详情页

java自定义注解

浏览:31日期:2023-11-02 16:49:17

问题描述

比如springmvc的requestmapping

//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)//

package org.springframework.web.bind.annotation;

import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.springframework.core.annotation.AliasFor;

@Target({ElementType.METHOD, ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Mappingpublic @interface RequestMapping {

String name() default '';@AliasFor('path')String[] value() default {};@AliasFor('value')String[] path() default {};RequestMethod[] method() default {};String[] params() default {};String[] headers() default {};String[] consumes() default {};String[] produces() default {};

}

为什么就可以将请求 路由进来啊 实现代码在哪儿呢 什么原理啊???

问题解答

回答1:

如果不了解注解相关的知识,可以了解一下注解知识 1、文章1,2、文章2,这两篇讲解的还不错。之后可以百度一下spring mvc requestmapping 源码解读,网上的文章还是蛮多的。源码目前还没有读过,不过基本的原理应该也是通过反射获取到相应的配置,再根据配置进行请求路由。具体的是怎么根据反射获取相应配置的还是要去读一下源码。

回答2:

/a/11...

标签: java
相关文章: