整合Mubatis-Plus
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user