1 Star 0 Fork 140

szw / auto-code

forked from ztp / auto-code 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

auto-code

欢迎使用auto-code代码自动生成引擎.2.1.0 再次升级.现在生成代码不再需要书写yaml文件.直接可以通过页面生成 单表, 一对一, 一对多 ,多对多代码 源码地址 代码生成演示地址

目录

  1. 项目介绍
    1. 项目的优势在哪里
    2. 什么情况选择该项目
    3. 为何会发起该项目
    4. 如果您觉得项目还行.请点赞.您的支持是我最大的动力项目地址
  2. 集成教程
    1. 使用教程
      1. 准备工作
      2. 单表生成
      3. 一对一代码生成 one-to-one
      4. 一对多 代码生成 one-to-Many
      5. 多对多 代码生成 many-to-many
    2. 生成代码注意事项
  3. 配置参数介绍

更新日志

2019-03-21: 版本:2.1.0 生成代码增加可视化视图,不再需要写yaml文件配置了

2019-03-18: 版本:2.0.2 增加swagger api配置

1.yaml 文件 globalConfig 增加 swagger:true 
2.集成swagger(具体请看实例代码.或者百度),访问 http://localhost:8080/swagger-ui.html#/

项目介绍

项目的优势在哪里

1.目前市面上的代码生成工具绝大多数仅仅支持生成单表,该项目支持 单表, 一对一, 一对多 ,多对多 代码生成.大大简化了开发的工作量

2.只要目前你的项目采用 springMVC+spring+mybatis架构的项目都适用(传统工程和springBoot工程都适用). 不管一次开发还是二次开发.该项目仅仅只是帮你生成单表以及多表的增删改查,不做任何底层的改动.

什么情况选择该项目

1.该项目只生成接口(controller,service,serviceImpl,dao,xml), 不生成页面.所以如果项目是采用前后台分离,不需要写页面.该项目会适合你

2.如果还想生成页面请看该项目,这个项目基于本项目.扩展了页面生成.适合后台使用 源码地址 演示地址 账号 ztp 密码 111111

为何会发起该项目?

绝大多数时候我们都是在做增删改查.每次创建一张表.然后我们需要重新写一次增删改查, 写虽然简单,不过极度耗时(controller,server,serverImpl,dao,xml) 所以才有了该项目,该项目能帮助你减少70%的工作量,让你专注于业务的实现.

如果您觉得项目还行.请点赞.您的支持是我最大的动力项目地址

start

集成教程

非常简单.只需要短短的几部就能完成集成

1.传统java-web集成请看这里 项目地址

2.spring-boot集成请看这里 项目地址

使用教程

准备工作

1.集成非常简单请查看上面的项目.选择自己需要的方式.里面有实例工程可供参考

2.成功后访问 http://localhost:8070/auto-code-ui/ui/index.html

界面如下: global

单表生成

假设我们要生成一张单表

CREATE TABLE `test_simple_code` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `name` varchar(50) DEFAULT NULL COMMENT '名称',
  `age` int(3) DEFAULT NULL COMMENT '年龄',
  `status` int(2) DEFAULT NULL COMMENT '{"name":"状态","1":"启用","0":"禁用"}',
  `birthday` date DEFAULT NULL COMMENT '生日',
  `remarks` text COMMENT '备注',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='单表代码生成';

1.在数据库建表

  1. 界面选择单表生成.选择对应的表,点击生成预览. 最后点击确认生成. 完毕.

simple

生成的文件如下: select

3.生成完毕

一对一代码生成 one-to-one (代码采用追加的方式.无需担心代码被覆盖)

一个用户对应一个班级

CREATE TABLE `test_one_to_one_user` (
  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `name` VARCHAR(50) DEFAULT NULL COMMENT '名称',
  `age` INT(3) DEFAULT NULL COMMENT '年龄',
  `status` INT(2) DEFAULT NULL COMMENT '{"name":"状态","1":"启用","0":"禁用"}',
  `birthday` DATE DEFAULT NULL COMMENT '生日',
  `remarks` TEXT COMMENT '备注',
  `mun` DECIMAL(20,2) DEFAULT NULL COMMENT '数字',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8 COMMENT='一对一用户';

CREATE TABLE `test_one_to_one_class` (
  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '班级id',
  `user_id` INT(11) DEFAULT NULL COMMENT '用户id',
  `class_name` VARCHAR(50) DEFAULT NULL COMMENT '班级名称',
  `quantity` INT(11) DEFAULT NULL COMMENT '班级人数',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='一对一班级';
  1. 打开界面.选择对应的表,一对一比单表多了一个外键id. 比如上面两张表的关系就是通过 user_id来关联的 如下:
test_one_to_one_user.id=test_one_to_one_class.user_id

one-to-one one-to-one

一对多 代码生成 one-to-Many (代码采用追加的方式.无需担心代码被覆盖)

一对多一对一一样不再描述

多对多 代码生成 many-to-many (代码采用追加的方式.无需担心代码被覆盖)

多个用户 对应 多个角色

CREATE TABLE `test_many_to_many_role` (
  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '角色',
  `name` VARCHAR(100) NOT NULL COMMENT '角色名称',
  `status` INT(2) DEFAULT '0' COMMENT '{"name":"状态","0":"启用","1":"禁用"}',
  `create_user_id` INT(11) DEFAULT NULL COMMENT '创建者',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` INT(11) DEFAULT NULL COMMENT '更新者',
  `update_time` DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `dels` INT(2) DEFAULT '0' COMMENT '{"name":"是否删除","0":"正常","1":"删除"}',
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COMMENT='多对多角色';

CREATE TABLE `test_many_to_many_user` (
  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `name` VARCHAR(50) DEFAULT NULL COMMENT '名称',
  `age` INT(3) DEFAULT NULL COMMENT '年龄',
  `status` INT(2) DEFAULT NULL COMMENT '{"name":"状态","1":"启用","0":"禁用"}',
  `birthday` DATE DEFAULT NULL COMMENT '生日',
  `remarks` TEXT COMMENT '备注',
  `mun` DECIMAL(20,2) DEFAULT NULL COMMENT '数字',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8 COMMENT='多对多用户';

CREATE TABLE `test_many_to_many_user_role` (
  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '测试用户角色',
  `user_id` INT(11) DEFAULT NULL COMMENT '用户id',
  `role_id` INT(11) DEFAULT NULL COMMENT '角色id',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=140 DEFAULT CHARSET=utf8 COMMENT='多对多用户角色';

1.打开界面.选择对应的表,多对多一对一多了一个关系描述表 比如上面三张表的关系是通过 test_many_to_many_user_role来表述的.如下:

test_many_to_many_user_role.user_id=test_many_to_many_user.id and test_many_to_many_user_role.role_id=test_many_to_many_role.id

many-to-many many-to-many many-to-many

生成代码注意事项

1.创建表结构时如果写上表与字段的注释将大大增加程序的可读性.我会将注释写到bean上面.
2.如果注释为json键值对字符串我将会在实体类生成一个字典方法
如:  {"1":"启用","0":"禁用"} 将会在实体类里面生成:
    public String getStatus_(){
		if(MyStringUtils.isEmpty(status)){
			 return "";
		}else if(status.equals("1")){
			return "启用";
		}else if(status.equals("0")){
			return "禁用";
		}
		return "";

	}

配置参数介绍

如果是spring boot请以auto-code.xx 开头.如:

auto-code.cover=false
或者
 auto-code:
    cover: false

如果是java web请使用yaml格式书写 如:

 globalConfig: 
    parentPack
参数名 默认值 介绍
parentPack 生成代码的父包 如父包是com.zengtengpeng.test controller将在com.zengtengpeng.test.controller下 bean 将在com.zengtengpeng.test.bean下 ,service,dao同理
parentPath 生成代码的项目根路径
cover false 是否覆盖生成 默认不覆盖
swagger true 是否生成swagger注解 (spring boot下如果为false将无法查看swagger页面)
javaSource src/main/java java在项目中的源路径
resources src/main/resources resource位置
xmlPath mybatisMapper mybatis xml存放的路径
packageBean bean 生成bean尾缀
packageDao dao 生成dao尾缀
packageController controller 生成controller尾缀
packageService service 生成service尾缀
packageBean bean 生成bean尾缀
autoCode true 是否启用代码生成器(生成环境建议关闭)
watchMobel false 观察者模式.只能看.不能生成代码(演示环境用的)

996.icu

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. [http://fsf.org/] Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

java代码自动生成器 ,通过页面生成 单表,一对一,一对多,多对多代码.支持无限级联,支持所有关系型数据库.支持spring-boot整合 展开 收起
Java
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/qcwcn/auto-code.git
git@gitee.com:qcwcn/auto-code.git
qcwcn
auto-code
auto-code
master

搜索帮助

14c37bed 8189591 565d56ea 8189591