Baidu Encyclopedia
Active Record is a domain model pattern characterized by an entity class corresponding to a table in a relational database, and an entity class instance corresponding to the data in the table. ActiveRecord strictly follows the standard ORM model: tables map to entity objects, and columns map to entity object properties.
create project
引入SpringBoot devtoos, lombok,spring web,spring data jdbc ,mysql driver,mybatis Framework
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>mybatis-plusar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mybatis-plusar</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</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>3.0.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.properties
#热部署生效
spring.devtools.restart.enabled=true
#设置重启目录
spring.devtools.restart.additional-paths=src/main/java
#排除目录
spring.devtools.restart.exclude=static/**
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=123456
#Mybatis-plus配置
#指定实体包名
mybatis-plus.type-aliases-package=com.example.mybatisplusar.mapper
#指定.xml路径
mybatis-plus.mapper-locations=classpath:/mapper/*.xml
#开启驼峰命名
mybatis-plus.configuration.map-underscore-to-camel-case=true
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#mybatis配置
#mybatis.mapper-locations=classpath:/mapper/*.xml
##配置模型路径
#mybatis.type-aliases-package=com.example.mybatisplus.pojo
##开启驼峰命名
#mybatis.configuration.map-underscore-to-camel-case=true
#Spring 框架自带的日志框架(Spring Framework Logging)
#logging.level.com.example.mybatisplus=debug
#http://localhost:8080/actuator/health
management.endpoint.health.show-details=always
general structure
Active Record Regulations
A table corresponds to an entity class, and each object instance of the class corresponds to a row of records in the table;
ActiveRecord itself is an entity class, and at the same time implements a persistent API, which can implement CRUD logic by itself
Implementation steps:
1. The entity class inherits Model<T> and specifies the generic type
2. The interface implements BaseMapper<T>, and specifies the generic type
specific demonstration
Added the default snowflake algorithm
Revise
Inquire