参考有关博客:
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>