因项目中action参数过多,并且是一些通用的查询参数,所以准备进行对参数统一封装为Map对象,然后由action中传入service中进行处理,查询spring的资料发现可以通过实现HandlerMethodArgumentResolver进行数参数的绑定,参考文章《扩展SpringMVC以支持更精准的数据绑定1》进行配置后。

项目调试中发现断点不能正常进行解析器,跟踪源代码找到在org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.getArgumentResolver()方法中会获取所有已经加载的解析器,会顺序执行,而我使用的Map对象会被spring自带的解析器给处理掉,所以自定义的解析器无法进入,HandlerMethodArgumentResolverComposite关键代码:

    private HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {
HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter);
if (result == null) {
for (HandlerMethodArgumentResolver methodArgumentResolver : this.argumentResolvers) {
if (logger.isTraceEnabled()) {
logger.trace("Testing if argument resolver [" + methodArgumentResolver + "] supports [" +
parameter.getGenericParameterType() + "]");
}
if (methodArgumentResolver.supportsParameter(parameter)) {
result = methodArgumentResolver;
this.argumentResolverCache.put(parameter, result);
break;
}
}
}
return result;
}

其中this.argumentResolvers为LinkedList变量,元素内容:

[org.springframework.web.method.annotation.RequestParamMethodArgumentResolver@9dc12fc,
org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver@23c893fc,
org.springframework.web.servlet.mvc.method.annotation.PathVariableMethodArgumentResolver@456b97be,
org.springframework.web.servlet.mvc.method.annotation.PathVariableMapMethodArgumentResolver@1ab75e8d,
org.springframework.web.servlet.mvc.method.annotation.MatrixVariableMethodArgumentResolver@7ca088ae,
org.springframework.web.servlet.mvc.method.annotation.MatrixVariableMapMethodArgumentResolver@f6d976e,
org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor@63f0beab,
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor@5275ffcf,
org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver@40ed9954,
org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver@2eed7b19,
org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver@692cbe60,
org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueMethodArgumentResolver@7886c691,
org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver@58569768,
org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver@1cee5a27,
org.springframework.web.servlet.mvc.method.annotation.ServletResponseMethodArgumentResolver@6460c547,
org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor@d37ebcd,
org.springframework.web.servlet.mvc.method.annotation.RedirectAttributesMethodArgumentResolver@5259e682,
org.springframework.web.method.annotation.ModelMethodProcessor@c2c8b0b,
org.springframework.web.method.annotation.MapMethodProcessor@405c856b,
org.springframework.web.method.annotation.ErrorsMethodArgumentResolver@7a3b54cf,
org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver@4d3d20ba,
org.springframework.web.servlet.mvc.method.annotation.UriComponentsBuilderMethodArgumentResolver@682fbaf3,
com.catt.web.springmvc.RequestMapResolver@159adcf5,
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver@6a2063e7,
org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor@747f091f]

红色标注出来的RequestParamMapMethodArgumentResolver为处理Map参数的解析器,处理关键代码:

    public boolean supportsParameter(MethodParameter parameter) {
RequestParam requestParamAnnot = parameter.getParameterAnnotation(RequestParam.class);
if (requestParamAnnot != null) {
if (Map.class.isAssignableFrom(parameter.getParameterType())) {
return !StringUtils.hasText(requestParamAnnot.value());
}
}
return false;
}
Map.class.isAssignableFrom会拦截实现Map接口的参数,所以我自定义的解析器始终无法断点进入。

HandlerMethodArgumentResolver数据绑定无效的更多相关文章

  1. ListBox数据绑定无效

    public class DataList { public List<string> listSource; private DataTable table; public DataLi ...

  2. vue数据绑定html

    html标签的纯文本显示/被当做html标签处理: 1)使用两个大括号时,假如字符串内容是html标签,那么不会被转义: 2)使用三个大括号时,字符串内的html标签会被直接转义 a.两个大括号: & ...

  3. Vuejs——(2)Vue生命周期,数据,手动挂载,指令,过滤器

    (八)传入的数据绑定 先创建一个对象(假如是obj),然后将他传入Vue实例中,作为data属性的值,那么 ①obj的值的变化,将影响Vue实例中的值的变化: ②相反一样: ③可以在Vue实例外面操纵 ...

  4. Vuejs——Vue生命周期,数据,手动挂载,指令,过滤器

    版权声明:出处http://blog.csdn.net/qq20004604   目录(?)[+]   原教程: http://cn.vuejs.org/guide/instance.html htt ...

  5. VS2015中DataGridView的DataGridViewComBoboxCell列值无效及数据绑定错误的解决方法

    在VS2015中练习DataGridView的使用, 发现其中的DataGridViewComBoboxCell列存在着绑定数据库列后出现值无效的提示 根据网上的解决办法,添加了DataError后可 ...

  6. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  7. GridView的七种数据绑定列的类型

    1.BoundField 用于显示普通文本,是默认的数据绑定列的类型,一般自动生成的列就是该类型,需要注意是DataFormatString属性,该属性可以设置显示的格式,常见格式有:{0:C} 设置 ...

  8. WPF:指定的命名连接在配置中找不到、非计划用于 EntityClient 提供程序或者无效的解决方法

    文/嶽永鹏 WPF 数据绑定中绑定到ENTITY,如果把数据文件做成一个类库,在UI文件中去应用它,可能遇到下面这种情况. 指定的命名连接在配置中找不到.非计划用于 EntityClient 提供程序 ...

  9. AngularJS笔记---数据绑定

    一.数据绑定 1.简单绑定 下面实现了一个简单的加法运算的绑定, A.ng-app:表示该div以内都在AngularJS的应用, 去掉ng-app="" 那么后面的绑定都将无效 ...

随机推荐

  1. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  2. U盘启动笔记本无法安装Win7问题和解决

    用“大白菜”工具制作启动U盘,从U盘启动后进入Win PE环境安装Win7,提示“安装win7系统安装程序无法创建新的系统分区,也无法定位现有系统分区”.经以下各种努力后仍无法正常安装: 在BIOS里 ...

  3. innosetup安装之前关闭进程

    InnoSetup覆盖安装的时候可能会因为源程序正在运行而安装失败,以下脚本能够关闭原运行进程. [code] // 安装前检查关闭**进程 function InitializeSetup():Bo ...

  4. Windows下提升进程权限

    windows的每个用户登录系统后,系统会产生一个访问令牌(access token) ,其中关联了当前用户的权限信息,用户登录后创建的每一个进程都含有用户access token的拷贝,当进程试图执 ...

  5. 解决 Android Studio 乱码问题

    http://www.eoeandroid.com/thread-275485-1-1.html 很多同学都安装了Android Studio,但是发现中文是乱码,其实这个很好解决的.在IDE里点击F ...

  6. malloc钩子和内存泄漏工具mtrace、Valgrind

    一:malloc钩子函数 static void* (* old_malloc_hook) (size_t,const void *);static void (* old_free_hook)(vo ...

  7. 几种filter的比较

    需要整理 Gaussian filter https://en.wikipedia.org/wiki/Gaussian_filter Laplacian/Laplacian of Gaussian h ...

  8. 多线程之ReentrantReadWriteLock

    java5以后在java.util.concurrent包下,有很多的并发类,可以让我们摆脱java5时,笨重的写法来满足多线程,而且提供了更加丰富的使用场景能力 其中,在locks包下,提供了 Re ...

  9. RDD分区2GB限制

    本文目的   最近使用spark处理较大的数据时,遇到了分区2G限制的问题(ken).找到了解决方法,并且在网上收集了一些资料,记录在这里,作为备忘.   问题现象   遇到这个问题时,spark日志 ...

  10. jackson 注脚学习参考

    (1)初级我们从几个简单的使用场景开始:重命名属性,忽略属性,以及修改属性所使用的类型.注意:下面的例子仅仅显示了成员属性(field properties),注解同样也可以用在成员方法(getter ...