SpringMVC数据绑定大全

查看spring源码可以看出spring支持转换的数据类型已经很多了.


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

/**

     * Actually register the default editors for this registry instance.

     */

    private void doRegisterDefaultEditors() {

        this.defaultEditors = new HashMap<Class, PropertyEditor>(64);

        // Simple editors, without parameterization capabilities.

        // The JDK does not contain a default editor for any of these target types.

        this.defaultEditors.put(Charset.class, new CharsetEditor());

        this.defaultEditors.put(Class.class, new ClassEditor());

        this.defaultEditors.put(Class[].class, new ClassArrayEditor());

        this.defaultEditors.put(Currency.class, new CurrencyEditor());

        this.defaultEditors.put(File.class, new FileEditor());

        this.defaultEditors.put(InputStream.class, new InputStreamEditor());

        this.defaultEditors.put(Locale.class, new LocaleEditor());

        this.defaultEditors.put(Pattern.class, new PatternEditor());

        this.defaultEditors.put(Properties.class, new PropertiesEditor());

        this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor());

        this.defaultEditors.put(TimeZone.class, new TimeZoneEditor());

        this.defaultEditors.put(URI.class, new URIEditor());

        this.defaultEditors.put(URL.class, new URLEditor());

        // Default instances of collection editors.

        // Can be overridden by registering custom instances of those as custom editors.

        this.defaultEditors.put(Collection.class, new CustomCollectionEditor(Collection.class));

        this.defaultEditors.put(Set.class, new CustomCollectionEditor(Set.class));

        this.defaultEditors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class));

        this.defaultEditors.put(List.class, new CustomCollectionEditor(List.class));

        this.defaultEditors.put(SortedMap.class, new CustomMapEditor(SortedMap.class));

        // Default editors for primitive arrays.

        this.defaultEditors.put(byte[].class, new ByteArrayPropertyEditor());

        this.defaultEditors.put(char[].class, new CharArrayPropertyEditor());

        // The JDK does not contain a default editor for char!

        this.defaultEditors.put(char.class, new CharacterEditor(false));

        this.defaultEditors.put(Character.class, new CharacterEditor(true));

        // Spring‘s CustomBooleanEditor accepts more flag values than the JDK‘s default editor.

        this.defaultEditors.put(boolean.class, new CustomBooleanEditor(false));

        this.defaultEditors.put(Boolean.class, new CustomBooleanEditor(true));

        // The JDK does not contain default editors for number wrapper types!

        // Override JDK primitive number editors with our own CustomNumberEditor.

        this.defaultEditors.put(byte.class, new CustomNumberEditor(Byte.class, false));

        this.defaultEditors.put(Byte.class, new CustomNumberEditor(Byte.class, true));

        this.defaultEditors.put(short.class, new CustomNumberEditor(Short.class, false));

        this.defaultEditors.put(Short.class, new CustomNumberEditor(Short.class, true));

        this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false));

        this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true));

        this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false));

        this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true));

        this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false));

        this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true));

        this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false));

        this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true));

        this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));

        this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));

        // Only register config value editors if explicitly requested.

        if (this.configValueEditorsActive) {

            StringArrayPropertyEditor sae = new StringArrayPropertyEditor();

            this.defaultEditors.put(String[].class, sae);

            this.defaultEditors.put(short[].class, sae);

            this.defaultEditors.put(int[].class, sae);

            this.defaultEditors.put(long[].class, sae);

        }

    }

来自为知笔记(Wiz)

时间: 2024-11-29 12:52:00

SpringMVC数据绑定大全的相关文章

SpringMVC数据绑定全面示例(复杂对象,数组等)

点击链接查询原文 http://www.xdemo.org/springmvc-data-bind/ 已经使用SpringMVC开发了几个项目,平时也有不少朋友问我数据怎么传输,怎么绑定之类的话题,今天做一个总结.在此之前,大家可以看一下我之前的一篇关于Spring restful的文章http://www.xdemo.org/spring-restful/. 项目下载:http://pan.baidu.com/share/link?shareid=955245807&uk=1896630845

SpringMvc 数据绑定400错误

今天请求一个SpringMvc 的时候,客户端总是报出: The request sent by the client was syntactically incorrect 网上都是说的是bean的名字和表单的名字不一样,但是我检查了N多遍之后,还是有报这个异常,就想到了SpringMvc 自动装配的问题. 然后看日志说是""转为int类型的时候不可以为空: 应该就是数据绑定的问题了,经过一番研究,springMvc的数据绑定有几种方式: 1,controller 独享 2,全局共享

springmvc数据绑定

一.创建工程,搭建springmvc 1. 配置wem.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns="http://java.sun.com/xml/ns/javaee"     xsi:schemaLocation=&qu

初学springMVC注解大全

请求路径上有个id的变量值,可以通过@PathVariable来获取 @RequestMapping(value = "/page/{id}", method = RequestMethod.GET) @RequestParam用来获得静态的URL请求入参 spring注解时action里用到. 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri tem

SpringMVC数据绑定(链接)

http://www.cnblogs.com/xd502djj/archive/2013/08/08/3245485.html http://os.51cto.com/art/201205/339166.htm

(SpringMVC)报错:The request sent by the client was syntactically incorrect ()

springMVC数据绑定,对我们而言,能够更轻松的获取页面的数据,但是必须要注意的一点就是: Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写 在Controller中@RequestParam("m_level") Integer m_level 那么在jsp页面上的数据 <select name="m_level"> <option value="一级">一级</opti

Springmvc简单入门

SpringMVC 目录 一.         HelloWorld以及前期相关的配置工作... 3 二.         RequestingMapping修饰类... 4 三.         RequestMapping修饰请求头.请求参数等... 4 四.         RequestMapping支持通配符的情况antPAth. 6 五.         使用PathVariable. 6 六.         HiddenHttpMethodFilter. 6 七.        

springMVC能做什么,做j2ee时候要考虑什么

转载: http://jinnianshilongnian.iteye.com/category/231099 [置顶] 跟我学SpringMVC目录汇总贴.PDF下载.源码下载 博客分类: 跟开涛学SpringMVC 电子书下载链接 请登录后下载   在线版目录 第一章 Web MVC简介 第二章 Spring MVC入门 第三章 DispatcherServlet详解 2012-12-22 08:05 浏览 188903 评论(91) 收藏 分类:企业架构 源代码下载——第七章 注解式控制器

Java从零打造企业级电商项目实战-服务端

第1章 课程介绍(导学,项目演示,课程安排,架构演进)本章详细介绍Java服务端课程的内容,项目演示(http://www.happymmall.com),然后还介绍下课程安排,最后会讲解一下高大上的架构是如何一步一步从一台服务器演变到高性能.高并发.高可用架构的过程并讲解在这过程中大型架构演进思想以及代码演进细节....第2章 开发环境安装与配置讲解.实操(linux,windows)本章将手把手领大家在windows和linux环境下安装jdk.tomcat.maven.vsftpd.ngi