一、CustomEditorConfigurer类

CustomEditorConfigurer可以读取实现java.beans.PropertyEditor接口的类,将字符串转为指定的类型。更方便的可以使用PropertyEditorSupport。PropertyEditorSupport实现PropertyEditor接口,必须重新定义setAsText。

public class Hello {
private String message;
private User user; public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}

自定义属性编辑器继承PropertyEditorSupport类,重写setAsText方法。

public class UserEditor extends PropertyEditorSupport{
@Override
public void setAsText(String text) throws IllegalArgumentException {
//类型为User的变量声明了自定义属性编辑器,其值规定为逗号分割的字符串
String[] arr = text.split(",");
Integer age = new Integer(arr[1]); User user = new User();
user.setName(arr[0]);
user.setAge(age); setValue(user);
}
}

bean配置

<bean id="configBean"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<!-- 类型为User的变量都通过UserEditor间接设值 -->
<entry key="User">
<bean id="userEditor" class="UserEditor"/>
</entry>
</map>
</property>
</bean> <bean id="hello" class="Hello">
<property name="message" value="hello" />
<property name="user" value="chenjumin,20"/><!-- 类型为User的变量声明了自定义属性编辑器,其值规定为逗号分割的字符串 -->
</bean>

Spring常用的接口和类(三)的更多相关文章

  1. Spring常用的接口和类(一)

    一.ApplicationContextAware接口 当一个类需要获取ApplicationContext实例时,可以让该类实现ApplicationContextAware接口.代码展示如下: p ...

  2. Spring常用的接口和类(二)

    七.BeanPostProcessor接口 当需要对受管bean进行预处理时,可以新建一个实现BeanPostProcessor接口的类,并将该类配置到Spring容器中. 实现BeanPostPro ...

  3. Spring 常用的一些工具类

    学习Java的人,或者开发很多项目,都需要使用到Spring 这个框架,这个框架对于java程序员来说.学好spring 就不怕找不到工作.我们时常会写一些工具类,但是有些时候 我们不清楚,我们些的工 ...

  4. JavaWeb学习之JDBC API中常用的接口和类

    JDBC API中包含四个常用的接口和一个类分别是: 1.Connection接口 2.Statement接口 3.PreparedStatement接口 4.ResultSet接口 5.Driver ...

  5. Servlet常用的接口和类

    使用接口和类的作用:Servlet也是依靠继承父类和实现接口来实现的.使用Servlet必须要引入两个包:javax.servlet和javax.servlet.http.所有的Servlet应用都是 ...

  6. Spring:Spring项目多接口实现类报错找不到指定类

    spring可以通过applicationContext.xml进行配置接口实现类 applicationContext.xml中可以添加如下配置: 在application.properties中添 ...

  7. 07.Hibernate常用的接口和类---Session接口☆☆☆☆☆

    一.特点 Session是在Hibernate中使用最频繁的接口.也被称之为持久化管理器.它提供了和持久化有关的操作,比如添加.修改.删除.加载和查询实体对象 Session 是应用程序与数据库之间交 ...

  8. servlet学习之servletAPI编程常用的接口和类

    ServletConfig接口: SevletConfig接口位于javax.servlet包中,它封装了servlet配置信息,在servlet初始化期间被传递.每一个Servlet都有且只有一个S ...

  9. 04.Hibernate常用的接口和类---SessionFactory类和作用

    是一个生成Session的工厂类 特点: 1.由Configuration通过加载配置文件创建该对象. SessionFactory factory = config.buildSessionFact ...

随机推荐

  1. ASP.NET MVC 5 入门教程 (3) 路由route

    文章来源: Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc-5-get-started-route.html 上一节:ASP.NET MVC 5 入门 ...

  2. 7.HBase In Action 第一章-HBase简介(1.2.1 典型的网络搜索问题:Bigtable的起原)

    Search is the act of locating information you care about: for example, searching for pages in a text ...

  3. sublime 插件的安装

    sublime(text3)插件的安装 之前一直对sublime插件的安装搞不懂,导致自己不能充分地运用它的便捷性.昨天仔细看了下百度,恍然大悟,一下子把必备的插件都装了: 对于插件的安装,首先要在s ...

  4. 【前端开发系列】—— CSS3属性选择器总结

    想想自己为什么要学CSS,作为一个开发过前端的人员来说,调试一个图片花了半天的时间,最后发现分隔符用错了,实在是一件很丢人的事情.因此,痛下决心来学习CSS,最近一周也会更新下相关的学习笔记. CSS ...

  5. c# TextBox只允许输入数字,禁用右键粘贴,允许Ctrl+v粘贴数字

    TextBox只允许输入数字,最大长度为10 //TextBox.ShortcutsEnabled为false 禁止右键和Ctrl+v private void txtNumber_KeyPress( ...

  6. Python安装、配置图文详解(转载)

    Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境(I ...

  7. Ibatis学习总结4--SQL Map XML 映射文件扩展

    SQL Map XML 映射文件除了上文提到的属性还有一些其他重要的属性,下文将详细介绍这些属性. 缓存 Mapped Statement 结果集 通过在查询 statement 中指定 cacheM ...

  8. MyEclipse8.5快速搭建SSH框架

    来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...

  9. [转]DBA,SYSDBA,SYSOPER三者的区别

    原文地址:http://www.oracleonlinux.cn/2010/02/dba_sysdba_sysoper/ 什么是DBA?什么是SYSDBA,什么又是SYSOPER?三者究竟有何联系呢? ...

  10. Asp.Net MVC 中实现跨域访问

    在ASP.Net webapi中可以使用  Microsoft.AspNet.WebApi.Cors  来实现: public static class WebApiConfig { public s ...