导入依赖
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version></dependency><dependency><groupId>com.gitee.sunchenbin.mybatis.actable</groupId><artifactId>mybatis-enhance-actable</artifactId><version>1.1.1.RELEASE</version></dependency>
application.yml
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/db01?serverTimezone=UTC&characterEncoding=utf8
driver-class-name:com.mysql.jdbc.Driver
username: root
password: root
mybatis:
table:
auto: update
#create系统启动后,会将所有的表删除掉,然后根据model中配置的结构重新建表,该操作会破坏原有数据。
#update系统会自动判断哪些表是新建的.哪些字段要修改类型等,哪些字段要删除,哪些字段要新增,该操作不会破坏原有数据。#none系统不做任何处理。
#add新增表/新增字段/新增索引新增唯一约束的功能,不做做修改和删除(只在版本1.0.9.RELEASE及以上支持)。model:
model:
pack: com.qs.entity #扫描用于创建表的对象的包名,多个包用"."隔开
database:
type: mysql #数据库类型目前只支持mysql
mybatis-plus:
#1.如果是mybatis直接在mybatis下增加该配置。
#2.如果使用properties配置方式,要写成mapperLocations
mapper-locations: classpath*:mapper/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml #第一个是自己写xml的路径,第二个是固定的
启动类上添加注解
@MapperScan({"com.gitee.sunchenbin.mybatis.actable.dao.*"})//固定的@ComponentScan("com.gitee.sunchenbin.mybatis.actable.manager.*")//固定的@SpringBootApplicationpublicclassMybatistestApplication{publicstaticvoidmain(String[] args){SpringApplication.run(MybatistestApplication.class, args);}}
公共父类
importcom.baomidou.mybatisplus.annotation.IdType;importcom.baomidou.mybatisplus.annotation.TableId;importcom.gitee.sunchenbin.mybatis.actable.annotation.Column;importcom.gitee.sunchenbin.mybatis.actable.annotation.IsAutoIncrement;importcom.gitee.sunchenbin.mybatis.actable.annotation.IsKey;/**
* @author qingshi
* @date 2023/1/6 11:21
* info:
*/publicclassBaseModle{@TableId(type =IdType.AUTO)@IsKey@IsAutoIncrement@ColumnprivateInteger id;@Column(name ="create_time",comment ="创建时间")privateString createTime;@Column(name ="updaet_time",comment ="修改时间")privateString updaetTime;publicIntegergetId(){return id;}publicvoidsetId(Integer id){this.id = id;}publicStringgetCreateTime(){return createTime;}publicvoidsetCreateTime(String createTime){this.createTime = createTime;}publicStringgetUpdaetTime(){return updaetTime;}publicvoidsetUpdaetTime(String updaetTime){this.updaetTime = updaetTime;}}
实体类
importcom.gitee.sunchenbin.mybatis.actable.annotation.Column;importcom.gitee.sunchenbin.mybatis.actable.annotation.Table;/**
* @author qingshi
* @date 2023/1/6 11:24
* info:
*/@Table(name ="people")publicclass people extendsBaseModle{@Column(comment ="姓名")privateString name;@ColumnprivateString sex;publicStringgetName(){return name;}publicvoidsetName(String name){this.name = name;}publicStringgetSex(){return sex;}publicvoidsetSex(String sex){this.sex = sex;}}
运行后自动建表(更新表)
本文转载自: https://blog.csdn.net/weixin_44758923/article/details/128576149
版权归原作者 青莳吖 所有, 如有侵权,请联系我们删除。
版权归原作者 青莳吖 所有, 如有侵权,请联系我们删除。