【发布时间】:2018-12-07 19:22:38
【问题描述】:
我尝试关注Return HashMap in mybatis and use it as ModelAttribute in spring MVC(选项1)和Mybatis ResultMap is HashMap<String,Object>。我有
@Select("select sources.host as 'key', count(*) total ... group by host")
@MapKey("key")
Map<String, Integer> getSourcesById(@Param("id")String id, @Param("hitDate")Date hitDate);
返回错误
尝试从结果集中获取列“键”时出错。原因:java.sql.SQLException:getInt() 的值无效 - 'NONE' ; SQL []; getInt() 的值无效 - 'NONE';嵌套异常是 java.sql.SQLException: Invalid value for getInt() - 'NONE'
查询在 MySQL 中运行良好并返回
| key | total |
+-------------+-------+
| NONE | 33 |
| twitter.com | 1 |
好像没有使用@MapKey注解。
我试过了
List<AbstractMap.SimpleEntry<String, Integer>> getSourcesById(...)
但它给了
嵌套异常是 org.apache.ibatis.executor.ExecutorException: No constructor found in java.util.AbstractMap$SimpleEntry matching [java.lang.String, java.lang.Long]
也尝试过同样的错误。
List<AbstractMap.SimpleEntry<String, Long>>
https://docs.oracle.com/javase/7/docs/api/java/util/AbstractMap.SimpleEntry.html#constructor_summary
MyBatis 3.4.6、MyBatis-Spring 1.3.2
【问题讨论】: