SpringBoot+通用Mapper+Thymeleaf+Bootstrap整和遇到的问题
pom.xml:
主要是依赖jar包的配置
<dependencies>
<!--web依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--Mybatis依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<!--数据库连接依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
<scope>runtime</scope>
</dependency>
<!--单元测试依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 通用mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
<!-- thymeleaf依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
application.yml文件配置:
此处导入的是mysql5.1.32版本的jar包因此仍然写旧的包名
#端口配置
server:
port: 8080
spring:
#jdbc配置
datasource:
#新版mysql包名:com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver
#新版mysql需要设置时区:&serverTimezone=GMT
url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8
username: root
password: root
#thymeleaf配置
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
encoding: utf-8
mode: HTML5
servlet:
content-type: text/html
#springboot 引入js 和css 失效问题
mvc:
static-path-pattern: /static/**
#mybatis配置
mybatis:
#实体类所在包名
type-aliases-package: com.example.domain
#通用mapper配置
mapper:
identity: MYSQL
遇到的主要问题:
在login.html页面导入本地的静态资源无法访问的问题
login.html页面导入本地静态资源
<link rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}">
<script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
<script src="../static/js/jquery-3.2.1.min.js" th:src="@{/js/jquery-3.2.1.min.js}"></script>
将静态资源导入后,必须重新Rebuild资源,否则静态资源无法加载。