主要的操作步骤:
1、pom.xml下载好项目所需的依赖包
// 启动项目必备
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
//mysql依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
//mybatis-plus 依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
//如果你的项目中使用了 MyBatis Plus,但没有添加 MyBatis Plus Generator 依赖,那么就无法使用 MyBatis Plus Generator 代码生成器。
//这意味着你将不得不手动编写实体类、Mapper 接口、Service 类和 XML 映射文件等代码,这将耗费大量的时间和精力。
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.1</version>
</dependency>
2、yml文件做好相关配置:
server:
port: 9088
spring:
application:
name: demo
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/hospital?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
mybatis-plus:
configuration:
map-underscore-to-camel-case: true #
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: assign_id
3、编写实体层
4、编写Mapper层
5、编写控制器层
**
在 IDEA 中,当我们修改了代码后,有时候确实需要重启应用程序才能使代码更新生效。但也有一些情况下,代码更新无需重启就可以实现。下面介绍一些能在 IDEA 中实现代码热更新的方法:
**
1、使用 Spring Boot DevTools 模块
Spring Boot DevTools 模块可以帮助我们在开发过程中自动重启应用程序,从而使代码更新生效,而不必手动重启应用程序。在 Maven 项目中添加如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
然后在pom.xml文件中这样执行一下:此方法目前不生效
PS: 如何mybatis-plus本身封装的方法无法满足自身需求,需要自定义的话,需要怎么做?
1、新建UserMapper.xml
2、在UserMapper自定义方法
3、在控制器调用此自定义方法