整合Mubatis-Plus
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
<spring-cloud-alibaba.version>2022.0.0.0</spring-cloud-alibaba.version>
|
<spring-cloud-alibaba.version>2022.0.0.0</spring-cloud-alibaba.version>
|
||||||
<spring-cloud.version>2022.0.0</spring-cloud.version>
|
<spring-cloud.version>2022.0.0</spring-cloud.version>
|
||||||
<jackson.version>2.16.1</jackson.version>
|
<jackson.version>2.16.1</jackson.version>
|
||||||
|
<mysql-connector-java.version>8.0.29</mysql-connector-java.version>
|
||||||
|
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 统一依赖管理 -->
|
<!-- 统一依赖管理 -->
|
||||||
@@ -101,6 +103,19 @@
|
|||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Mybatis-Plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MySQL 驱动 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>${mysql-connector-java.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,16 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Mybatis-Plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- MySQL 驱动 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -46,6 +56,18 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.xml</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package top.crushtj.xiaoyishu.auth.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hanfuye
|
||||||
|
* @title MyBatisConfig
|
||||||
|
* @date 2025/11/27
|
||||||
|
* @description MybatisPlus配置类
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@MapperScan("top.crushtj.**.mappers")
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
/**
|
||||||
|
* 分页插件
|
||||||
|
*
|
||||||
|
* @return MybatisPlusInterceptor
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package top.crushtj.xiaoyishu.auth.domain.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ayi
|
||||||
|
* @title UserEntity
|
||||||
|
* @date 2025/11/27
|
||||||
|
* @description 用户测试表
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("t_user")
|
||||||
|
public class UserEntity implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 403394297290102294L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@TableId("ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@TableField("USERNAME")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField("CREATE_TIME")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField("UPDATE_TIME")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package top.crushtj.xiaoyishu.auth.domain.mappers;
|
||||||
|
|
||||||
|
import top.crushtj.xiaoyishu.auth.domain.entity.UserEntity;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ayi
|
||||||
|
* @title 用户测试表
|
||||||
|
* @date 2025/11/27
|
||||||
|
* @description (t_user)表数据库访问层
|
||||||
|
*/
|
||||||
|
public interface UserMapper extends BaseMapper<UserEntity> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="top.crushtj.xiaoyishu.auth.domain.mappers.UserMapper">
|
||||||
|
|
||||||
|
<resultMap type="top.crushtj.xiaoyishu.auth.domain.entity.UserEntity" id="UserMap">
|
||||||
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
||||||
|
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
<!-- 所有列的SQL片段 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,username,create_time,update_time
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
spring:
|
|
||||||
application:
|
|
||||||
name: xiaoyi-auth
|
|
||||||
output:
|
|
||||||
ansi:
|
|
||||||
enabled: always
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
spring:
|
|
||||||
profiles:
|
|
||||||
active:
|
|
||||||
- dev
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# 数据库连接信息
|
||||||
|
url: jdbc:mysql://10.0.0.3:3306/xiaoyishu?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
|
username: xiaoyi
|
||||||
|
password: HhpxE2HWE4bGTyB5
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
top.crushtj.xiaoyishu.auth.domain.mappers: debug
|
||||||
|
mybatis-plus:
|
||||||
|
mapper-locations:
|
||||||
|
- classpath*:top/crushtj/**/*.xml # 匹配所有模块中的 Mapper XML 文件
|
||||||
|
type-aliases-package: top.crushtj.xiaoyishu.auth.domain.entity # 实体类包路径
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true # 开启驼峰命名转换
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志输出(调试用)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
spring:
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
server:
|
||||||
|
port: 18080
|
||||||
@@ -1,13 +1,34 @@
|
|||||||
package top.crushtj.xiaoyishu.auth;
|
package top.crushtj.xiaoyishu.auth;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import top.crushtj.xiaoyishu.auth.domain.entity.UserEntity;
|
||||||
|
import top.crushtj.xiaoyishu.auth.domain.mappers.UserMapper;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
class XiaoyiAuthApplicationTests {
|
class XiaoyiAuthApplicationTests {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
UserMapper userMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testInsert() {
|
||||||
|
UserEntity user = UserEntity.builder()
|
||||||
|
.username("刑加一")
|
||||||
|
.createTime(LocalDateTime.now())
|
||||||
|
.updateTime(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
userMapper.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user