Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Thymeleaf中添加换行符或新行?_Java_Html_Spring_Spring Boot_Thymeleaf - Fatal编程技术网

Java 如何在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中,我将使用标记来创建中断。但它似乎

这是我使用Thymeleaf模板的代码

<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
方法——即使您认为您的特定用例可能是安全的。