美文网首页
jdbcTemplate.queryForList(String

jdbcTemplate.queryForList(String

作者: Badgg | 来源:发表于2020-05-22 10:50 被阅读0次

这个elementType不支持我们自定义的类型Class对象,

org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1,     actual 8:Incorrect column count: expected 1, actual94

翻看spring的官方文档

官方文档

好家伙,只支持基本数据类型

想了想,这样的话难道要拿出来map再转一次实体?

可以自己写个反射来转,也可以用fastJson来转

那难道真的要用回原始的解决方案吗?spring这么厉害没有方法吗?

有,

官方文档

没错,就是这个query方法,传入一个RowMapper来完成字段映射

List res =this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper<>(Demo.class));

相关文章

网友评论

      本文标题:jdbcTemplate.queryForList(String

      本文链接:https://www.haomeiwen.com/subject/jynfahtx.html