JPA查询自定义字段报错 could not execute query....Column 'id' not found(thymeleaf遍历map、th:href)返回值类型改成Map

参考有关博客:
thymeleaf遍历数组对象,通过超链接将对象的某个属性当作参数再传到Controller层

1.问题描述
执行这句报错:

@Query(value="SELECT DATE_FORMAT(include_date,'%Y年%m月') AS includeDateStr,COUNT(*) AS articleCount FROM t_article GROUP BY DATE_FORMAT(include_date,'%Y年%m月') ORDER BY  DATE_FORMAT(include_date,'%Y年%m月') DESC",nativeQuery=true)
public List<Article> getCountList();

但是在sqlyog里面执行是正确的:
在这里插入图片描述
2.解决办法
搞了半天,发现,将返回值改成Map<String,Object>才可以正常查到数据:
在这里插入图片描述
在这里插入图片描述
3.thymeleaf遍历mapList 取值:

<ul th:each="entries,stat : ${application.articleCountMapList}" th:style="'background-color:'+@{${stat.odd}?'#F2F2F2'}" >
    <a href="#" th:href="@{/article/list/1(includeDateStr=${entries['includeDateStr']})}">
       <li th:text="${entries['includeDateStr']}+'('+${entries['articleCount']}+')'"></li>
    </a>
</ul>
发布了98 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37767455/article/details/103076519