【发布时间】:2019-09-09 06:34:24
【问题描述】:
我得到类型集合的 toArray 方法未定义当我有来自查询的多行时。当它只有一行时工作正常。我使用的是 Java 11。
jdbcTemplate.query(sql,
new EntityRespRowMapper());
这是我的 RowMapper 类
public class EntityRespRowMapper implements RowMapper<EntityResponse>{
@Override
public EntityResponsemapRow(ResultSet rs, int rowNum) throws SQLException {
EntityResponse entity = new EntityResponse();
entity.setEntity_id(rs.getLong("entity_id"));
entity.setValue(rs.getString("value"));
entity.setId(rs.getLong("id"));
entity.setEnd_date(rs.getDate("end_date"));
return entity ;
}
}
我在这里做错了什么。有人可以帮我吗。我也试过 QueryForList。它给出了同样的问题。
【问题讨论】:
-
请完整的堆栈跟踪 ;)
-
没有堆栈跟踪。当我进行数据库调用时,我在响应对象中看到了这个错误。
-
我刚刚意识到您的 RowMapper 类不会编译(在“构造函数”末尾显式返回) - 我认为它不应该是构造函数
-
你的意思是
EntityResponse对象的value字段包含这个字符串吗?那么这意味着它就是您的数据库包含的内容。如果不是,请澄清。我们看不到你的屏幕。所以你需要准确地解释你在做什么,你期望发生什么以及会发生什么。 -
你到底在哪里使用 toArray()?正确的语法是将空数组作为参数传递。也许这就是问题所在?
标签: java jdbc spring-jdbc jdbctemplate