先上报错代码
String resultStr = "";
Map<String, Object> map = new HashMap<String, Object>();
map.put("pageIndex", 1);
map.put("pageSize", 2);
map.put("title", content);
PageInfo<Article> articleList = articleService.query(map); // 查询列表
if (articleList.getList().size() == 0) {
String str = "回答内容不超过200字" + content;
if (wordService.getWord(str) != null) {
resultStr = wordService.getWord(str);
}
} else {
List<Article> list = articleList.getList();
logger.info(list);
// 这里报错 java.util.HashMap cannot be cast to com.XXX.XXX
for (Article article : list) {
Article art = articleService.find(article.getId());
resultStr = art.getContent();
}
}
service层代码
import java.util.Map;
public interface ArticleService {
// 分页查询
PageInfo<Article> query(Map<String, Object> paramMap);
}
问题原因处在mybatis
问题代码
<!-- 获取文章列表 这里不获取content 内容太多 -->
<select id="query" parameterType="java.util.Map" resultType="com.hi.hailiaowenan.affair.bean.Article">
select id, title, description, images,
create_time as createTime, update_time as updateTime
from
<include refid="table_name"></include>
</select>
一开始我是用resultType="java.util.Map"作为返回类型
<select id="query" parameterType="java.util.Map" resultType="java.util.Map">
所以报错,要改成自己的类
<!-- 获取文章列表 这里不获取content 内容太多 -->
<select id="query" parameterType="java.util.Map" resultType="com.hi.hailiaowenan.affair.bean.Article">
select id, title, description, images,
create_time as createTime, update_time as updateTime
from
<include refid="table_name"></include>
</trim>
</select>