Spring mvc 如何在spring MVC中实现面包屑&;百里香
嗨,朋友们,我需要你们的帮助,在我的项目SpringMVC、JPA、thymeleaf中实现面包屑。我发现示例项目很有用,但我被困在这里了Spring mvc 如何在spring MVC中实现面包屑&;百里香,spring-mvc,breadcrumbs,Spring Mvc,Breadcrumbs,嗨,朋友们,我需要你们的帮助,在我的项目SpringMVC、JPA、thymeleaf中实现面包屑。我发现示例项目很有用,但我被困在这里了 <c:forEach var="entry" items="${sessionScope.currentBreadCrumb}"> <c:choose> <c:when test="${entry.currentPage == true}"> ${entry.label}
<c:forEach var="entry" items="${sessionScope.currentBreadCrumb}">
<c:choose>
<c:when test="${entry.currentPage == true}">
${entry.label}
</c:when>
<c:otherwise>
<a href="${entry.url}">${entry.label}></a>
</c:otherwise>
</c:choose>
</c:forEach>
${entry.label}
上面的代码是用JSP编写的。既然我使用的是thymeleaf,有人能帮我用thymeleaf编写这个逻辑吗?或者还有其他更好的方法在SpringMVC项目中实现breadcrumbs吗?这篇文章看起来有点老了,但基本上你要找的是一种在thymeleaf中迭代集合的方法。最近,我使用bootstrap和Thymeleaf做了一些非常类似的事情
<ul class="breadcrumb" >
<li th:each="entry : ${sessionScope.currentBreadCrumb}">
<a th:href="${entry.queryString}" th:unless="${entry.isCurrent}" th:text="${entry.label}">Home</a>
<span th:if="${entry.isCurrent}" th:text="${entry.label}">Home</span>
</li>
</ul>
-
家
查看此代码snipet,您可以通过使用thymeleaf属性th:除非来控制链接(href)的外观。span标记以类似的方式使用thymeleaf属性th:if
“th:除非”相当于使用“th:if”进行否定检查。这确实是一个偏好的问题
如果您对条件逻辑有疑问,请查看以下链接:
看看它是如何遍历集合的,您将看到th:each=“entry:${sessionScope.currentBreadCrumb}”的使用,它位于列表项标记内;条目成为currentBreadCrumb集合的迭代器
如果您有关于如何迭代的问题,请再次查看此链接:
干杯 你的问题是什么?你坚持什么?你发的代码有什么问题吗你有什么例外吗。?如果有任何问题,请张贴在您的问题。我正试图实现上述代码在thymeleaf。