spring-springJDBC的queryForObject查找对象出错
错误提示:
Exception in thread 'main' org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 13
错误位置:
Contract contract =jdbc.queryForObject("select * from contract where id=15",Contract,class);
测试过程:
刚开始以为我建的类的属性和表中的字段不匹配,我又对了好几遍发现没错;又以为Contract 类中金额属性为int类型太小,可是发现还不是这里的问题。
解决方法:
RowMapper<Contract > rm = ParameterizedBeanPropertyRowMapper.newInstance(Contract . class );
Contract contract = (Contract ) this .jdbcTemplate.queryForObject(
"select * from contract where id=15"
, rm);
|
这是为什么呢?
参考网站:http://www.cnblogs.com/wumian/articles/2012-10-25-2056.html