mybatis-enhance-actable根据字段创建表格
2022-10-09 本文已影响0人
Leo_23
Java的ssm项目使用mybatis-enhance-actable根据字段创建表格
1.添加依赖
<dependency>
<groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
<artifactId>mybatis-enhance-actable</artifactId>
<version>1.5.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
</exclusion>
</exclusions>
</dependency>
2.yml添加配置参数
# 使用 mybatis-enhance-actable 配置 https://www.yuque.com/sunchenbin/actable/ag3y1y
actable:
table:
auto: update
model:
pack: com.leo23.entity
database:
type: mysql
index:
prefix:
unique:
prefix:
- 实体类编写
package com.leo23.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@TableName("customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_UUID)
@Column(comment = "主键id")
private String id;
@Column(comment = "客户简称")
private String short_name;
@Column(comment = "客户名称")
private String name;
@Column(comment = "地址")
private String address;
@Column(comment = "城市")
private String city;
@Column(comment = "电话")
private String phone;
@Column(comment = "网站")
private String website;
@Column(comment = "感兴趣的产品")
private String interestProduct;
@Column(comment = "备注")
private String note;
@Column(comment = "添加时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime add_time;
@Column(comment = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime update_time;
}
- 启动文件添加扫描
package com.leo23;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
//mapper接口路径
@MapperScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.dao.*", "com.leo23.mapper"})
//扫包路径
@ComponentScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.manager.*", "com.leo23.*"})
public class JserpApplication {
public static void main(String[] args) {
SpringApplication.run(JserpApplication.class, args);
}
}