这里主要是为了解决我前面遇到的问题,因为在默认注解DefaultAnnotationHandlerMapping的determineUrlsForHandlerMethods方法中遇到了RelectionUtils的doWith方法,在
determineUrlsForHandlerMethods方法中调用的时候,有两个参数,一个是
Class对象,一个是
new
ReflectionUtils.MethodCallback() ,这里的MethodClallback是ReflectionUtils的内部回调接口,它用于处理从Class的对象获取的Method对象。
public interface MethodCallback {
/**
* Perform an operation using the given method.
* @param method the method to operate on
*/
void doWith(Method method) throws IllegalArgumentException, IllegalAccessException;
}
public static void doWithMethods(Class<?> clazz, MethodCallback mc) throws IllegalArgumentException {
doWithMethods(clazz, mc, null);
}
然后就主要来看真正的内容doWithMethods,第三个参数这里没用到,它也是RelectionUtils内部接口
public interface MethodFilter {
/**
* Determine whether the given method matches.
* @param method the method to check
*/
boolean matches(Method method);
}
/**
* Perform the given callback operation on all matching methods of the given
* class and superclasses.
* <p>The same named method occurring on subclass and superclass will appear
* twice, unless excluded by the specified {@link MethodFilter}.
* @param clazz class to start looking at
* @param mc the callback to invoke for each method
* @param mf the filter that determines the methods to apply the callback to
*/
public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf)
throws IllegalArgumentException {
// Keep backing up the inheritance hierarchy.
Class<?> targetClass = clazz;
do {
Method[] methods = targetClass.getDeclaredMethods();
for (Method method : methods) {
if (mf != null && !mf.matches(method)) {
continue;
}
try {
mc.doWith(method);
}
catch (IllegalAccessException ex) {
throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName()
+ "': " + ex);
}
}
targetClass = targetClass.getSuperclass();
}
while (targetClass != null);
}
遍历类的所有Method,对其进行doWith,这里doWith就由自己实现了。
分享到:
相关推荐
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。Spring MVC4是当前zuixin的版本,在众多特性上有了进一步的提升。, 在精通Spring...
Spring MVC源码深度剖析开源架构源码2021.pdf
Mastering Spring MVC 4(2015.09)源码
spring mvc源码框架,绝对可以运行。
spring mvc mybatis 整合源码,带数据库脚本,带详细注释,适合初、中、高各级开发人员使用
Spring mvc、 Spring、 Spring jdbc 整合实例源码
Spring MVC是Spring框架中用于Web应用快速开发的一个模块,其中的MVC是Model-View-Controller的缩写。作为当今业界最主流的Web开发框架,Spring MVC已经成为当前最热门的开发技能,同时也广泛用于桌面开发领域。 ...
学习Spring MVC,关于注解的Spring MVC,简单例子,关于控制器的Spring MVC,学习Spring,简单Spring MVC实例
以下这个学习案例是我最近学习Spring MVC时跟从一本 书上的示例,原文中的示例代码有一些小错误,不过我 在调试的过程中已经给予了修正,如还有其它错误,还 请各位批评指正。 对于现有较成熟的Model-View-...
Spring MVC是Spring框架中用于Web应用快速开发的一个模块,其中的MVC是Model-View-Controller的缩写。作为当今业界最主流的Web开发框架,Spring MVC已经成为当前最热门的开发技能,同时也广泛用于桌面开发领域。 ...
spring MVC基础学习
Spring MVC 基础实例源码01 我的博客上SpringMVC基础教程 实例的源码
通俗移动的Spring MVC入门书籍。请尊重版权,禁止用于商业目的。
Spring.MVC-A.Tutorial-Spring.MVC学习指南 高清可复制版PDF
Spring mvc jar包
Spring MVC 学习记录总结Spring MVC 是目前主流的实现MVC设计模式的框架,是Spring 框架的一个分支产品,以 Spring IoC 容器
easyUI+Hibernate+Spring MVC源码
本文详细介绍spring MVC的原理和开发心得体会。
maven+ibatis+spring mvc源码