Intention
在Java项目中,一个功能只要和表相关,即使它是一个很小的功能,也可能需要多层结构。所以当我们创建一个表时,意味着我们需要创建一系列JAVA文件,如Entity/DAO/Service/Controller等。而这样的工作很多都是类似的,而这样重复的功能有时会让我们觉得枯燥,对个人也难以有很大的提示,但这确实业务中最重要,却又无法避免工作.因此我们需要对这样的工作做一些简化,比如定制一套模板,然后根据模板和具体表去生成业务代码;而table2crud可以较好地帮助我们完成这些重复枯燥的工作,项目地址[https://github.com/liusf1993/table2crud],目前可以从JAVA最好用的IDE, Intellij Idea的插件(Plugins)中搜索table2crud
下载插件安装.
Quick start
这里我们以User表举例说明如何使用
create table user
(
user_id bigint auto_increment not null
primary key comment '用户ID',
user_name varchar(50) not null comment '用户名',
password varchar(50) not null comment '密码',
region_id int not null comment '所在地区ID',
cellphone varchar(64) not null comment '电话号码',
state int not null comment '状态',
create_time bigint not null comment '创建时间',
modified_time bigint not null comment '修改时间'
)
- 安装好插件后,我们通过Tools->table2crud 或使用快捷键
ALT+SHIFT+U
进入工具
以下面是主页面
2.在最后一个tab页填入数据源信息
3.输入关键字查询表
4.点击按钮 Analysis from DataSrouce
5. 表结构
6. 生成文件
7. 生成文件未格式化,需要手动格式化 ctrl+alt+l
8. 生成文件大致是这样
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XKgUbhYB-1618471081719)(https://raw.githubusercontent.com/liusf1993/table2crud/master/docs/screenshot//10.dao.png)]