'spring.thymeleaf.servlet.content-type' является неизвестным свойством - PullRequest
0 голосов
/ 09 июня 2018

Я запускаю свой первый весенний проект и использую sts как ide, я хочу использовать Thymeleaf для шаблонов страниц, но ссылка th: href работает не как ссылка, а как обычный текст, но я могу 'я не могу найти страницу, которую хочу и не могу перенаправить на страницу тимилиста:

#==================================
# = JSP Configuration
#==================================
#spring.mvc.view.prefix: /WEB-INF/views/
#spring.mvc.view.suffix: .jsp
#
#==================================
# = Thymeleaf configurations
#==================================
#spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
server.servlet.context-path=/
#
#==================================
# = Datasource configuration
#==================================
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
#spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
logging.level.org.springframework.web=INFO
#spring.jpa.hibernate.ddl-auto=create
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/siw
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#
#==================================
# = Webserver configuration
#==================================
server.port= 8080 
#
#==================================
# = Misc configuration
#==================================
spring.messages.basename=messages/validation
#
#==================================
# = Security configuration
#==================================
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
spring.security.user.name=paolo
spring.security.user.password=paolo

это Pom, который я использую для поиска и разрешения зависимости библиотек с помощью maven:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>it.uniroma3</groupId>
    <artifactId>progettoSIW</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>progettoSIW</name>
    <description>project for SIW</description>

    <!--    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath /> 
    </parent>
    -->

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/>
    </parent>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Как я могу это исправить, я использую в html это, чтобы указать использование thymeleaf: xmlns:th="http://www.thymeleaf.org"

PS Если я использую ... / resource / templates в качестве местоположения для индекса, я не могуНайди это;Мне нужно надеть это ... / resouces / static

1 Ответ

0 голосов
/ 09 июня 2018

добавить th: ref как это:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body><div class="starter-template">
    <h1>Spring Boot Web Thymeleaf Example</h1>
    <h2>
        <span th:text="'Message: ' + ${message}"></span>
        <a th:href="@{${link}}">view</a>
       <!-- <span th:link="${link}" th:text="${link}"></span>-->
    </h2>
</div>
</body>
</html>

Пожалуйста, обратитесь к рабочему коду для этого в здесь

И о вашем другом вопросе, настройке расположения пользовательского шаблона,вам нужно изменить файл application.properties следующим образом

spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/static/
spring.thymeleaf.suffix=.html
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...