pom引用
<?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>项目组</groupId> <artifactId>项目ID</artifactId> <version>项目版本</version> <name>项目名称</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</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-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
application.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/conduct_rules?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=ufsoft*123 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
#配置清除缓存,实现热部署。修改完html后一定要ctrl+f9重新build一下。再回到浏览器刷新,就能看到效果了。
spring.thymeleaf.cache=false
//Repository与Entities省略
参考:SpringBoot 使用JPA+MySQL+Thymeleaf 总结 二
thymeleaf模板
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"/> <title>标题</title> <link rel="stylesheet" th:href="@{/main.css}"/> <script th:src="@{/jquery.min.js}"></script> </head> <body> <div> <h2>hello thymeleaf</h2> <a th:href="@{http://127.0.0.1/appcontext?url={url}(url=${item.fileUrl})}" target="_blank">查看图片</a> </div> </body> </html>