BUG(Spring Framework JdbcTemplate) org.springframework.jdbc.IncorrectResultSetColumnCountException:

一.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);
}

 

posted @ 2019-03-18 22:02  蜜獾互联网  阅读(9)  评论(0编辑  收藏  举报  来源