Java 如何在Thymeleaf中添加换行符或新行?
这是我使用Thymeleaf模板的代码Java 如何在Thymeleaf中添加换行符或新行?,java,html,spring,spring-boot,thymeleaf,Java,Html,Spring,Spring Boot,Thymeleaf,这是我使用Thymeleaf模板的代码 <form> <label> <input type="checkbox" th:each="activeMeal : ${activeMeals}" th:text="${activeMeal.itemName}"> </label> </form> 这将生成: 我希望每个复选框在单独的一行中。在普通的纯HTML中,我将使用标记来创建中断。但它似乎
<form>
<label>
<input type="checkbox" th:each="activeMeal : ${activeMeals}" th:text="${activeMeal.itemName}">
</label>
</form>
这将生成:
我希望每个复选框在单独的一行中。在普通的纯HTML中,我将使用
标记来创建中断。但它似乎不在Thymeleaf标签内工作
<th:block th:each="activeMeal : ${activeMeals}">
<input type="checkbox" name="selectedActive" id="selectedActive" th:value="${activeMeal.itemName}"/>
<label th:text="${activeMeal.itemName}"></label>
<br/>
</th:block>
不要这样做,但是。。。可以使用th:utext
避免以字符串形式转义HTML。看见我说不要这样做是因为有风险。请参阅其中一条答案注释中的注释:“…使用utext会使您容易受到跨站点脚本攻击…”。我想出于这个原因,最好不要使用utext
方法——即使您认为您的特定用例可能是安全的。