Spring MVC中数据绑定(转)
Spring MVC中数据绑定
比如Product有一个createTime属性,是java.util.Date类型。那么最简单的转型处理是,在SimpleFormController中覆盖initBinder方法。如:
@Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Date.class, new CustomDateEditor( new SimpleDateFormat("yyyy-MM-dd"), true)); }
复用这部分代码的办法,可以编写自己的SimpleFormController子类,再以此为父类,所有表单的Controller通过继承复用。
或者,编写一个WebBindingInitializer的子类,比如:
public class MyBindingInitializer implements WebBindingInitializer { @Override public void initBinder(WebDataBinder binder, WebRequest request) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, true)); } }
然后配置到比如SimpleFormController中:
<bean name="/save.htm" class="product.SaveProductController"> <property name="formView" value="input" /> <property name="successView" value="redirect:/browse.htm" /> <property name="commandClass" value="product.Product" /> <property name="productDao" ref="productDao" /> <property name="webBindingInitializer"> <bean class="product.MyBindingInitializer"/> </property>
<bean/>
转自:http://marshal.easymorse.com/archives/1243
Spring MVC中数据绑定(转)的更多相关文章
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- Spring MVC中基于注解的 Controller
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...
- Spring MVC 中 @ModelAttribute 注解的妙用
Spring MVC 中 @ModelAttribute 注解的妙用 Spring MVC 提供的这种基于注释的编程模型,极大的简化了 web 应用的开发.其中 @Controller 和 @Rest ...
- spring mvc中DispatcherServlet如何得到ModelAndView的
首先看下面这种张图,这张图说明了spring mvc整体的流程. 本文讲的就是如何从DispatcherServlet中得到ModerAndView的过程. 首先看DispatherServlet这个 ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
- Java Web 学习(5) —— Spring MVC 之数据绑定
Spring MVC 之数据绑定 数据绑定是将用户输入绑定到领域模型的一种特性. Http 请求传递的数据为 String 类型,通过数据绑定,可以将数据填充为不同类型的对象属性. 基本类型绑定 @R ...
- Spring mvc中@RequestMapping 6个基本用法
Spring mvc中@RequestMapping 6个基本用法 spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: Java代码 @Reques ...
- spring mvc中使用freemark的一点心得
参考文档: FreeMarker标签与使用 连接http://blog.csdn.net/nengyu/article/details/6829244 freemarker学习笔记--指令参考: ht ...
- Http请求中Content-Type讲解以及在Spring MVC中的应用
引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...
随机推荐
- hdfs-over-ftp安装与配置
hdfs-over-ftp是一个开源,简单易用的实现了对HDFS系统的下载和上传功能的小工具.可以作为管理工具来使用,快捷方便. 1 安装jdk(1.6以上版本)并配置环境变量分别执行java -ve ...
- RCP打包出来 运行 出现 JVM terminated.exit code = 13
在建立PM.product,即打包时,没有添加相应的插件,导致无法运行
- Injector Job深入分析
Injector Job的主要功能是根据crawlId在hbase中创建一个表,将将文本中的seed注入表中. (一)命令执行 1.运行命令 [jediael@master local]$ bin/n ...
- php中利用HttpClient判断页面状态
$url = ''; $info = parse_url($url); $httpClient = new HttpClient($info['host']); $httpClient->get ...
- CloudStack核心类ApiServlet、ApiServer、ApiDispatcher、GenericDaoBase源码分析
ApiServlet 首先从整体上看下ApiServlet,Outline视图如下, 一.注意@Inject依赖的是javax.inject.jar,它和spring的@Autowired的区别在于使 ...
- Altium designer PCB king (收录各种版本)
不要再留念protel99se这么古老的PCB软件了,宝刀也经不起岁月的磨练. 相比Altium Designer,protel99se逊色多了.虽然很多人还是用这把已经快老的刀.作为新时代的新人,我 ...
- 《Programming WPF》翻译 第6章 1.创建和使用资源
原文:<Programming WPF>翻译 第6章 1.创建和使用资源 资源这个词具有非常广泛的意义.任何对象都可以是一个资源.一个在用户界面中经常使用的Brush或者Color可以是一 ...
- PowerShell_零基础自学课程_8_高级主题:WMI对象和COM组件
本系列文章从最初的初识开始,基本上可以完成一些简单的系统管理了,为了更方便的管理系统,同时为了更好的发掘系统的性能,就需要用到系统提供 的一些高级特性,在Windows Server系列的OS中,如果 ...
- flexbox自动完成
1.引入文件 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ty ...
- Hdu5785-Interesting(回文串处理)
Problem Description Alice get a string S. She thinks palindrome string is interesting. Now she wanna ...