A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

wxlkeepmoving

初级黑马

  • 黑马币:

  • 帖子:

  • 精华:

© wxlkeepmoving 初级黑马   /  2013-8-9 07:28  /  614 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

person bean是这样的:
  1. package cn.study.beanutils;

  2. import java.util.Date;

  3. public class Person {
  4.         private String name;
  5.         private int age;
  6.         private String password;
  7.         private Date birthday;
  8.        
  9.         public Date getBirthday() {
  10.                 return birthday;
  11.         }
  12.         public void setBirthday(Date birthday) {
  13.                 this.birthday = birthday;
  14.         }
  15.         public String getName() {
  16.                 return name;
  17.         }
  18.         public void setName(String name) {
  19.                 this.name = name;
  20.         }
  21.         public int getAge() {
  22.                 return age;
  23.         }
  24.         public void setAge(int age) {
  25.                 this.age = age;
  26.         }
  27.         public String getPassword() {
  28.                 return password;
  29.         }
  30.         public void setPassword(String password) {
  31.                 this.password = password;
  32.         }
  33.        
  34.        
  35. }
复制代码
用BeanUtils的第三方类库操作Java bean:
  1.         @Test
  2.         public void test2() throws Exception {
  3.                 Class clazz = Class.forName("cn.study.beanutils.Person");
  4.                 Person p = (Person) clazz.newInstance();

  5.                 ConvertUtils.register(new DateConverter(), Date.class);               
  6.                
  7.                 // setProperty
  8.                 //BeanUtils.setProperty(p, "name", "tome");
  9.                
  10.                 BeanUtils.setProperty(p, "birthday", "1999-01-01");               
  11.                 System.out.println(BeanUtils.getProperty(p, "birthday"));
  12.                
  13.         }
复制代码
运行时,有异常抛出,不知道为什么?
  1. org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion.
  2.         at org.apache.commons.beanutils.converters.DateTimeConverter.toDate(DateTimeConverter.java:468)
  3.         at org.apache.commons.beanutils.converters.DateTimeConverter.convertToType(DateTimeConverter.java:343)
  4.         at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156)
  5.         at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:470)
  6.         at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1006)
  7.         at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:456)
  8.         at cn.study.beanutils.Demo1.test2(Demo1.java:38)
  9.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  10.         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  11.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  12.         at java.lang.reflect.Method.invoke(Unknown Source)
  13.         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  14.         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  15.         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  16.         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  17.         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
  18.         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  19.         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  20.         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  21.         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  22.         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  23.         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  24.         at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  25.         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
  26.         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  27.         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  28.         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  29.         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  30.         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

复制代码
各位大侠,能帮忙看看问题吗?

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马