1. 找不到xml文件解决办法
因为我们没有配置所有SpringBoot启动默认是不加载mapper文件件的 所以我们在pom文件中配置以下
<dependencies>
<!--SpringBook所需的jar包-->
<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.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--MySql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
<scope>runtime</scope>
</dependency>
<!--通用Mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>RELEASE</version>
</dependency>
<!--配置分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
<!--热部署依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!--配置热部署-->
<configuration>
<fork>true</fork>
</configuration>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!--扫描mapper资源配置-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
application.yml 配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 1234
url: jdbc:mysql://127.0.0.1:3306/eyenet?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
#配置静态资源
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/
thymeleaf:
encoding: UTF-8
suffix: .html
cache: false
# 配置前缀时必须加templates,浏览器访问页面时不加templates路径
prefix: classpath:/templates/
#json转换日期
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
#上传文件
servlet:
multipart:
max-file-size: 1000MB
max-request-size: 1000MB
#分页
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: countSql
#设置mapper
mapper:
#关闭驼峰命名规则
style: normal
#添加MyBatis配置
mybatis:
mapper-locations: classpath:com/eyelesson/mapper/*.xml #配置映射文件
type-aliases-package: com.eyelesson.entity #配置实体类
#mybatis解决返回为HashMap或者LinkedHashMap时,某些结果集的字段null,导致map中少key的问题
configuration:
call-setters-on-nulls: true
启动类加注解扫描 dao层
2.Springboot热部署配置
file–>settings
这样热部署就配置完成了 不用每次更新代码都启动了
2.1 热部署配置一定要添加devtools依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
在 Spring 框架中,Spring Boot 提供了一个称为 Spring Boot DevTools 的模块,它可以帮助开发人员在开发过程中实现快速的热部署。热部署是指在应用程序运行时对代码进行更改后,应用程序会自动重新加载新的代码,而无需手动重新启动整个应用程序。
Spring Boot DevTools 中的热部署是基于类加载器的技术实现的。它会监视应用程序的类文件和资源文件的变化,当检测到这些文件发生变化时,它会重新加载修改过的类并重启应用程序的上下文,但不是整个应用程序。这意味着相比于传统的手动重启,Spring Boot DevTools 提供了更快速和方便的开发体验。
Spring Boot DevTools 实际上也是通过重启代码来实现热部署的,只不过它是在检测到代码变化后自动执行,而不需要手动启动整个应用程序
。