我正在运行我的第一个春季项目,而我'使用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 I用于查找和解决与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中使用这个来指定百里香的使用:
xmlns:th="http://www.thymeleaf.org"
P.S。如果我使用... / resource / templates作为索引的位置,我无法找到它;我需要把它放在...... / resouces / static
上答案 0 :(得分:0)
将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>
请在here
中查看相应的工作代码关于您的其他问题,设置自定义模板位置,您需要像这样修改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