Spring常用的接口和类(三)
一、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常用的接口和类(三)的更多相关文章
- Spring常用的接口和类(一)
一.ApplicationContextAware接口 当一个类需要获取ApplicationContext实例时,可以让该类实现ApplicationContextAware接口.代码展示如下: p ...
- Spring常用的接口和类(二)
七.BeanPostProcessor接口 当需要对受管bean进行预处理时,可以新建一个实现BeanPostProcessor接口的类,并将该类配置到Spring容器中. 实现BeanPostPro ...
- Spring 常用的一些工具类
学习Java的人,或者开发很多项目,都需要使用到Spring 这个框架,这个框架对于java程序员来说.学好spring 就不怕找不到工作.我们时常会写一些工具类,但是有些时候 我们不清楚,我们些的工 ...
- JavaWeb学习之JDBC API中常用的接口和类
JDBC API中包含四个常用的接口和一个类分别是: 1.Connection接口 2.Statement接口 3.PreparedStatement接口 4.ResultSet接口 5.Driver ...
- Servlet常用的接口和类
使用接口和类的作用:Servlet也是依靠继承父类和实现接口来实现的.使用Servlet必须要引入两个包:javax.servlet和javax.servlet.http.所有的Servlet应用都是 ...
- Spring:Spring项目多接口实现类报错找不到指定类
spring可以通过applicationContext.xml进行配置接口实现类 applicationContext.xml中可以添加如下配置: 在application.properties中添 ...
- 07.Hibernate常用的接口和类---Session接口☆☆☆☆☆
一.特点 Session是在Hibernate中使用最频繁的接口.也被称之为持久化管理器.它提供了和持久化有关的操作,比如添加.修改.删除.加载和查询实体对象 Session 是应用程序与数据库之间交 ...
- servlet学习之servletAPI编程常用的接口和类
ServletConfig接口: SevletConfig接口位于javax.servlet包中,它封装了servlet配置信息,在servlet初始化期间被传递.每一个Servlet都有且只有一个S ...
- 04.Hibernate常用的接口和类---SessionFactory类和作用
是一个生成Session的工厂类 特点: 1.由Configuration通过加载配置文件创建该对象. SessionFactory factory = config.buildSessionFact ...
随机推荐
- CUDA编程学习(二)
将数据加载到GPU后,如何在grid下的block进行并行计算(一个grid包含多个block) /****How do we run code in parallel on the device** ...
- [BZOJ 2241][SDOI2011]打地鼠(枚举+预处理)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2241 分析: 鉴于R,C的取值很小,于是可以人为枚举R和C的大小,然后判定这个规格的锤 ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- onethink常用标签的使用示例
首页文章模型列表输出: <article:list name="article" category="2" row="3" order ...
- 反射工具类——ReflectUtils
测试方法:根据已知的方法名,来反射调用方法 package com.redmoon.forum.job; import java.util.ArrayList; import java.util.Li ...
- Log4Net使用详解
1.Log4Net环境的搭建与基本配置 (1)Log4Net框架介绍 Log4net 是 Apache 下一个开放源码的项目,它是Log4j 的一个克隆版.我们可以控制日志信息的输出目的地.L ...
- Yii2提示信息设置方法
显示信息提示用户时,可以用setFlash,hasFlash,getFlash function actionOk() { Yii::app()->user->setFlash('succ ...
- 【转】mac os x系统上Android开发环境的搭建
由于Google官方已经不提供Adt-Bundle下载了,主推AndroidStudio.可以从这个链接下载http://www.androiddevtools.cn.上面不光有adt-bundle, ...
- PostConstruct
Spring AOP注解通过@Autowired,@Resource,@Qualifier,@PostConstruct,@PreDestroy注入属性的配置文件详解 1.6. @PostConstr ...
- 【poj2724】 Purifying Machine
http://poj.org/problem?id=2724 (题目链接) 题意 Mike有一个机器可以帮助他清理奶酪,每个奶酪由一个n位二进制数表示,机器上一共有n个按钮,每个按钮有1,0,*,其中 ...