2016-11-05 57 views
3

我有以下的HTML中:Thymeleaf燕子选项标签的DataList

<!DOCTYPE html> 
<html lang="es" xmlns:th="http://www.thymeleaf.org"> 
<head></head> 

<body> 

<input type = "text" name="city" id="city-selector" list="available-cities" autofocus/> 
    <datalist id="available-cities"> 
     <option value="1">Madrid</option> 
     <option value="2">Barcelona</option> 
     <option value="3">Sevilla</option> 
     <option value="4">Valencia</option> 

    </datalist> 

</body> 

</html> 

当我在春天启动的应用程序添加为静态内容,它的工作原理,我能够使用数据列表功能。但是,如果我一个Spring控制器请求添加此文件作为Thymeleaf模板,使用路由模板,DataList控件被呈现为以下几点:

<datalist id="available-cities"> Madrid Barcelona Sevilla Valencia </datalist> 

选项标签dissappear及其所有值连接。数据列表不再有效,因为没有选项标签。

这是一个Thymeleaf错误还是我做错了什么?

回答

3

看来这个问题与使用LilyCycleML5模式的Thymeleaf有关,如here的解释。

解决方法是use Thymeleaf 3避免使用nekohtml或,如果是不是一个选项,改变HTML5模式通过包括在application.properties以下行:

1

Thymeleaf 3解决了这个问题。默认情况下,春季Boot使用thymeleaf 2.下面的步骤应该做的工作:

在你application.properties补充:

spring.thymeleaf.mode=HTML 
spring.thymeleaf.cache=false 

,并在你的pom.xml添加:

<properties> 
    <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> 
    <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> 
</properties> 
<dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-actuator-docs</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-cache</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
</dependencies>