- VisualStudio2022插件的安装及使用-编程手把手系列文章
- pprof-在现网场景怎么用
- C#实现的下拉多选框,下拉多选树,多级节点
- 【学习笔记】基础数据结构:猫树
在开发过程中,总会涉及到数据库表结构字段的增加或者删除,或者是索引的增加和减少,这个时候能把修改表结构字段这些工作都交给程序来进行,那能大大方便开发。正好有一个现成的工具可以在springboot里面实现这个流程.
mybatis-enhance-actable 。
上述是gitee链接。这个工具是mybatis-enhance-actable,引用作者的介绍:A.CTable是一个基于Spring和Mybatis的Maven项目,mybatis-enhance-actable支持springboot,增强了Mybatis的功能,通过配置model注解的方式来创建表,修改表结构,提供通用的单表CUDR工具,实现了mybatis自动建表的能力,目前支持Mysql.
<dependency>
<groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
<artifactId>mybatis-enhance-actable</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
#自动建表设置
mybatis:
table:
#create系统启动后,会将所有的表删除掉,然后根据model中配置的结构重新建表,该操作会破坏原有数据;
#update系统会自动判断哪些表是新建的.哪些字段要修改类型等,哪些字段要删除,哪些字段要新增,该操作不会破坏原有数据;
#add新增表/新增字段/新增索引新增唯一约束的功能,不做做修改和删除(只在版本1.0.9.RELEASE及以上支持);
#none系统不做任何处理;
auto: update
model:
#扫描用于创建表的对象的包名 填入domain包路径
pack: com.xx.xx.domain
database:
#数据库类型目前只支持mysql
type: mysql
mybatis-plus: #数据库格式配置
global-config:
banner: false # 数据库启动的banner
db-config:
id-type: auto #id生成规则:mysql数据库id自增
configuration:
map-underscore-to-camel-case: true #开启驼峰,处理数据库“_"的字段
auto-mapping-behavior: full #自动映射任何复杂的结果
# 注意下面,一定要添加前面actable的xml
mapper-locations: com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml,classpath*:mapper/*.xml
@SpringBootApplication
@EnableScheduling
@EnableCaching
@MapperScan({"com.gitee.sunchenbin.mybatis.actable.dao.*", "com.*.*.mapper"})
@ComponentScan({"com.gitee.sunchenbin.mybatis.actable.manager.*", "com.*.*.*"})
public class ReceiveCardTestSystemApplication {
public static void main(String[] args) {
SpringApplication.run(ReceiveCardTestSystemApplication.class, args);
}
}
关键是这两行 。
@MapperScan({"com.gitee.sunchenbin.mybatis.actable.dao.*", "com.*.*.mapper"})
@ComponentScan({"com.gitee.sunchenbin.mybatis.actable.manager.*", "com.*.*.*"}) //扫描所有的包 最后一个是*,中间两个*换成实际路径
要增加上actable的扫包路径.
@Getter
@Setter
@Accessors(chain = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("users")
@Table(name = "users", isSimple = true)
public class UsersDO implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
@IsKey
@IsAutoIncrement
@Column(comment = "id")
private Integer id;
@Column(name = "user_name", length = 50, comment = "用户名", isNull = true)
@Index
private String userName;
@Column(name = "password", length = 255, comment = "密码", isNull = true)
private String password;
@Column(name = "employee_id", length = 50, comment = "工号", isNull = true)
@Unique
private String employeeId;
@Column(name = "role", comment = "0->管理员,1->测试员", isNull = true)
private Integer role;
@Column(name = "create_time", type = MySqlTypeConstant.DATETIME, isNull = true, comment = "创建时间")
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@Column(name = "update_time", type = MySqlTypeConstant.DATETIME, isNull = true, comment = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
注意
@Table(name = "users", isSimple = true) 。
当开启isSimple后 @Column里面不写name则会默认将驼峰命名改为下划线,比如updateTime变成了update_time 。
普通索引使用@Index,唯一索引使用@Unique 。
组合索引则这样使用:@Index(columns = {"country", "province", "city"}) 。
通过上述配置,启动系统的时候就会自动对MySQL表进行更新了.
最后此篇关于MyBatis实现MySQL表字段及结构的自动增删的文章就讲到这里了,如果你想了解更多关于MyBatis实现MySQL表字段及结构的自动增删的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
1.概述 转载:MyBatis 二级缓存全详解 上一篇文章中我们介绍到了 MyBatis 一级缓存其实就是 SqlSession 级别的缓存,什么是 SqlSession 级别的缓存呢?一级缓存的本质
1.概述 转载:核心配置综述之StatementHandler 2.MyBatis 四大组件之StatementHandler StatementHandler 是四大组件中最重要的一个对象,负责操作
1.概述 转载:MyBatis 启动流程 MyBatis 是第一个支持自定义 SQL、存储过程和高级映射的类持久框架。MyBatis 消除了大部分 JDBC 的样板代码、手动设置参数以及检索结果。My
1.概述 转载:MyBatis 基础搭建及架构概述 2.MyBatis 是什么? MyBatis是第一个支持自定义SQL、存储过程和高级映射的类持久框架。MyBatis消除了大部分JDBC的样板代码、
1.概述 转载:核心配置综述之 ParameterHandler MyBatis 四大核心组件我们已经了解到了两种,一个是 Executor ,它是MyBatis 解析SQL请求首先会经过的第一道关卡
1.概述 转载:核心配置综述之 ResultSetHandler 我们之前介绍过了MyBatis 四大核心配置之 Executor、StatementHandler、 ParameterHandler
如果我使用mybatis,我可以很容易地得到更新的行数,就像 update table set desc = 'xxx' where name = ? 但是,如果我想获取更新的行数,而不是计数,我该如
如何在MyBatis 3中使用小于等于 SELECT * FROM( SELECT * FROM TABLE1 WHERE COL1 =#{COL1,jdbc
我将 mybatis3.0.6 与 java 一起使用 哪个性能更好? [select id="getData" parameterType="Integer" resultType="Integer
我无法在 mybatis 中使用动态排序类型创建 SQL,如下例 select user_profile.user_profile_id, user_profile.first_name
这是一个流行的例子。 insert into ACCOUNT ( ACC_ID, ACC_FIRST_NAME, ACC_LAST_NAME, ACC_EMAIL )values (
我下载了MyBatis,文件夹中有一个mybatis-3.0.4-javadoc.jar,我解压并打开它,但它几乎是空的。 哪里可以找到MyBatis的API文档? 最佳答案 http://repo1
我正在尝试为 ArrayList 编写类型处理程序,但这给了我错误,任何人都可以帮助我。 我想将 ArrayList 作为 VARCHAR 存储在数据库中并将其检索为 ArrayList。 packa
目录 依赖 配置 CodeGenerator mybatis-plus-generator + clickhouse 自动生成代码 依赖
目录 三者实现对比 使用fluent mybatis 来实现上面的功能 换成mybatis原生实现效果 换成mybatis plus
例如,我有查询从员工中选择 ID、姓名、年龄、地址,而不是拥有员工对象列表。我希望有一个 map 列表,如 list{ map{ ("id", 123), ("name","jac
我在使 MyBatis (3.4.6) 工作时遇到一些麻烦。 我已将 mybatis-config.xml 文件放置在项目的 src/main/resources 文件夹中,但是当我运行单元测试时,出
我现在使用 Mybatis 和 spring-boot。我没有添加mybatis-config.xml。我根据说明通过 application.properties 为数据源和 mybatis 进行所
这是我的第一篇文章,用我糟糕的英语...... 我使用的是MyBatis3.0 在查询中,我使用 SqlBuilder 的方法如下: public class DataStatisticSqlBuil
主题:MyBatis:Boolean Paraeter:MyBatis 正在使用 Getter 内容: 大家好, 我一直在寻找解决我近乎简单的 MyBatis 问题的方法: 给定代码(仅必要部分):
我是一名优秀的程序员,十分优秀!