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>
123456789101112131415161718192021222324252627282930313233343536373839404142
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
1234567891011121314151617181920212223242526272829303132
遇到的主要问题:
在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>
123
将静态资源导入后,必须重新Rebuild资源,否则静态资源无法加载。
感谢大家看到这里,文章有不足,欢迎大家指出;如果你觉得写得不错,那就给我一个赞吧。
也欢迎大家关注我的公众号:Java程序员聚集地,麦冬每天都会分享java相关技术文章或行业资讯,欢迎大家关注和转发文章!