一.Spring Framework queryForObject 问题
1.spring4.0之前使用使用jdbctemplate 的queryForObject(String sql, Object[] args, RowMapper<T> rowMapper)
直接放入class类型会报错
org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 9
解决办法 封装一层 ParameterizedBeanPropertyRowMapper即可
2.spring framework 4.0之后的queryForObject 使用的是BeanPropertyRowMapper.newInstance(SysUser.class);也就意味着ParameterizedBeanPropertyRowMapper已经被BeanPropertyRowMapper取代
@Override
public <T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
List<T> results = query(sql, args, new RowMapperResultSetExtractor<T>(rowMapper, 1));
return DataAccessUtils.requiredSingleResult(results);
}