thymeleaf - 如何解析:text with whitespace to selectbox in thymeleaf?

标签 thymeleaf

我想使用具有以下值的选择框:

  <select th:field="*{branch}" name="branch" class="form-control" id="branch" required autofocus>
      <option th:value="'WEAiI'"th:text="Elektrotechniki Automatyki i Informatyki"></option>          
      <option th:value="'WBiA'"th:text="Budownictwa i Architektury"></option>
  </select>

当我调用我的方法时,我得到了这个异常:

 Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Could 
 not parse as expression: "Elektrotechniki Automatyki i Informatyki" 
 (template: "auth/register" - line 92, col 52)

当我使用“_”而不是空格时,一切正常。

我尝试像这样使用' ',但没有成功:

 <option th:value="'WBiA'"th:text="Budownictwa&nbsp;i&nbsp;Architektury">

有什么方法可以解析 thymeleaf 中 select 中带有空格的表达式吗?

最佳答案

用引号括起来,就像您对值所做的那样:

<select th:field="*{branch}" name="branch" class="form-control" id="branch" required autofocus>
    <option th:value="'WEAiI'" th:text="'Elektrotechniki Automatyki i Informatyki'" />
    <option th:value="'WBiA'" th:text="'Budownictwa i Architektury'" />
</select>

但在这种情况下,您确实不需要使用 th: 属性。你也可以做这样的事情。

<select th:field="*{branch}" name="branch" class="form-control" id="branch" required autofocus>
    <option value="WEAiI">Elektrotechniki Automatyki i Informatyki</option>          
    <option value="WBiA">Budownictwa i Architektury</option>
</select>

关于thymeleaf - 如何解析:text with whitespace to selectbox in thymeleaf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56481998/

相关文章:

java - Webflux Reactive 对象在渲染 Thymeleaf View 之前未解析

thymeleaf - 如何使用 Thymeleaf 在 Micronaut 中加载 css 文件?

java - 无法在 Spring mvc 中使用 Thymeleaf 解析 View

java - 如何从 thymeleaf 的 URL 中隐藏模型数据?

java - 有没有办法动态地将 id 插入 Thymeleaf 变量中?

java - 在 Spring Boot 应用程序中提供 HTML 页面

spring - 使用 thymeleaf 3 处理字符串模板

java - Thymeleaf:在 thymeleaf 中创建动态 URL 查询字符串

Thymeleaf 在没有span标签的html上打印实体属性

java - Thymeleaf:使用#dates.format() 函数来格式化具有国际化的日期。