快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记娱乐ag手机版_机器人论坛



Spring供给了一个BeanFactoryPostProcessor接口的实现类:CustomEditorConfigurer。这个类可以实现java.beans.PropertyEditor接口的类,和记娱乐ag手机版并将字符串值转换为指定类型的工具。

经由过程一个简单的例子来阐明。

导入Spring所需的包:commons-logging.jar,spring.jar 。(日志包和Spring包)

包下载地址:

http://www.blogjava.net/Files/ducklyl/Spring.rar

(1)创建User 类

package com.editor;

public class User {

private String name;

private int number;

pu和记娱乐ag手机版blic String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}

}

(2)创建HelloBean 类

package com.editor;

public class HelloBean {

private String helloWord;

private User user;

public String getHelloWord() {

return helloWord;

}

public void setHelloWord(String helloWord) {

this.helloWord = helloWord;

}

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

}

(3)创建UserEditor 类

package com.editor;

import java.beans.PropertyEditorSupport;

public class UserEditor extends PropertyEditorSupport{

public void setAsText(String text)

{

String[] strs=text.split(",");

int number=Integer.parseInt(strs[1]);

User user=new User();

user.setName(s和记娱乐ag手机版trs[0]);

us和记娱乐ag手机版er.setNumber(number);

setValue(user);

}

}

(4)在类路径下创建property-config.xml

Hello!

ducklyl,123和记娱乐ag手机版456

(5)创建测试类

package com.editor;

import org.springframework.context.*;

import org.springframework.context.support.*;

public class SpirngTest {

public static void main(String[] args)

{

//读取设置设置设备摆设摆设文件

您可能还会对下面的文章感兴趣: