@InitBinder 
  在controller中注册一个customer protperty editor以解析request中的参数并通过date bind机制与handler method中的参数做绑定。

@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}

Handler method代码如下

   @RequestMapping("/databind")
public ModelAndView databind1(Date date) {

}

访问url http://localhost:8080/springmvc/databind?date=2000-01-02 
通过initbinder中注册的customeDateEditor类型,自动将2000-01-02转换为日期类型

spring mvc自定义数据转换的更多相关文章

  1. 第6章 Spring MVC的数据转换、格式化和数据校验

    使用ConversionService转换数据 <%@ page language="java" contentType="text/html; charset=U ...

  2. Spring MVC自定义统一异常处理类,并且在控制台中输出错误日志

    在使用SimpleMappingExceptionResolver实现统一异常处理后(参考Spring MVC的异常统一处理方法), 发现出现异常时,log4j无法在控制台输出错误日志.因此需要自定义 ...

  3. spring mvc 自定义Handlermapping

    上次大概写了个可以解决velocity 多视图的东西. 但是实际运用过程中又到处找了些资料看了下.这里 小计下: DispatcherServlet解析过程: ..1..HandlerMapping. ...

  4. spring mvc 自定义编辑器

    起始知识: Java标准的PropertyEditor的核心功能是将一个字符串转换为一个Java对象,以便根据界面的输入或配置文件中的配置字符串构造出一个JVM内部的java对象. 如何注册自定义的属 ...

  5. spring mvc 自定义转换器

    <!-- 注册转化器 --> <mvc:annotation-driven conversion-service="conversionService" /> ...

  6. spring mvc自定义注解--登录时密码加密注解

    1,定义注解名称接口 /** * 使用该注解不用再MD5转换了 * * @author adonis * */ @Target(ElementType.PARAMETER) @Retention(Re ...

  7. Spring MVC 自定义类型转换器

    新建一个自定义转换器 import org.springframework.core.convert.converter.Converter; import org.springframework.s ...

  8. spring mvc --自定义converse

    在MVC中我们可以很轻松的根据项目需求进行必要的信息转换,如设置默认的日期格式,自定义String类型的格式等等... 配置中我们需要自定义converseService: <bean id=& ...

  9. Spring MVC自定义403,404,500状态码返回页面

    代码 HTTP状态码干货:http://tool.oschina.net/commons?type=5 import org.springframework.boot.web.servlet.erro ...

随机推荐

  1. POJ 1151 Atlantis 求矩阵面积并 扫描线 具体解释

    题意: 给定n个矩阵的左下角和右上角坐标,求矩阵面积并(矩阵总是正放的,即与x轴y轴都平行) 思路: 扫描线裸题 http://www.cnblogs.com/fenshen371/p/3214092 ...

  2. INDY10 IDHTTPSERVER返回中文不乱码

    INDY10 IDHTTPSERVER返回中文不乱码 procedure TynHttpServer.CommandGet(AContext: TIdContext; ARequestInfo: TI ...

  3. Nginx 作为反向Proxy 的优化要点

    原文地址:http://my.oschina.net/hyperichq/blog/405421 常用优化要点 当nginx用于反向代理时,每个客户端将使用两个连接: 一个用于响应客户端的请求,另一个 ...

  4. Python之“可变”的tuple

    前面我们看到了tuple一旦创建就不能修改.现在,我们来看一个"可变"的tuple: >>> t = ('a', 'b', ['A', 'B']) 注意到 t 有 ...

  5. arcgis python 创建 SQLite 数据库

    # -*- ################# """ Tool name: Create SQLite Database Source: CreateSQLiteDat ...

  6. java继承时候类的运行顺序问题

    子类在继承父类后,创建子类对象会首先调用父类的构造函数,先运行父类的构造函数,然后再运行子类的构造函数,例如以下所看到的: class Father{ public Father(){ System. ...

  7. 26个Jquery1.4使用小技巧

    1. 禁止右键点击 1.       $(document).ready(function(){ 2.           $(document).bind("contextmenu&quo ...

  8. Nodejs开发人脸识别系统-教你实现高大上的人工智能

    Nodejs开发人脸识别系统-教你实现高大上的人工智能   一.缘起缘生 前段时间有个H5很火,上传个头像就可以显示自己穿军装的样子,无意中看到了一篇帖子叫 全民刷军装背后的AI技术及简单实现 ,里面 ...

  9. Gedit

    Use Gedit as Remote File Editor via FTP and SSH Migrating from Windows Vista to Ubuntu 8.04 and have ...

  10. Installing Apache Spark on Ubuntu 16.04

    Santosh Srinivas on 07 Nov 2016, tagged onApache Spark, Analytics, Data Minin I've finally got to a ...