BeanPropertyRowMapper自动映射怎么不行呀?、急急急急
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import cn.jason.dbsuorce.MyDateSoure;
import cn.jason.vo.User;
/*
*
* 为什么用自动映射不行 new BeanPropertyRowMapper(User.class)
*/
public class BeanPropertyRowMapperTest extends JdbcDaoSupport{
JdbcTemplate jdbcTemplate = new JdbcTemplate(MyDateSoure.getDataSource());
public User findUserById(int id){
return (User)jdbcTemplate.queryForObject("select * from user where id=?", new Object[]{id},
new BeanPropertyRowMapper(User.class));
}
}
user 类
package cn.jason.vo;
public class User {
private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
测试类
package cn.junit;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import cn.jason.Dao.impl.BeanPropertyRowMapperTest;
public class BeanPropertyRowMapperTestTest {
BeanPropertyRowMapperTest dao;
@Before
public void setUp() throws Exception {
dao=new BeanPropertyRowMapperTest();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testFindUserById() {
System.out.println(dao.findUserById(5).getAge());
}
}
异常;
java.lang.IllegalArgumentException: Method must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.core.BridgeMethodResolver.findBridgedMethod(BridgeMethodResolver.java:65)
at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:59)
at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:250)
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:144)
at org.springframework.beans.BeanUtils.getPropertyDescriptors(BeanUtils.java:315)
at org.springframework.jdbc.core.BeanPropertyRowMapper.initialize(BeanPropertyRowMapper.java:134)
at org.springframework.jdbc.core.BeanPropertyRowMapper.<init>(BeanPropertyRowMapper.java:96)
at cn.jason.Dao.impl.BeanPropertyRowMapperTest.findUserById(BeanPropertyRowMapperTest.java:21)
at cn.junit.BeanPropertyRowMapperTestTest.testFindUserById(BeanPropertyRowMapperTestTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)