1 Star 0 Fork 28

XiaoXu / AutoGeneratorCode

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

AutoGeneratorCode

AutoGeneratorCode是一个代码生成引擎,可智能读取数据库信息,配合模板能够完成生成代码、编写文件等工作。
支持数据库所有表的批量生成,一键自动完成所有模板代码编写工作!支持自定义模板,生成任何你需要的文件格式。
已集成所有依赖包,只需导入一个jar,编写简单的配置即可使用。

作者:YouYuan
邮箱:xiyousuiyuan#163.com
QQ:1265161633

功能介绍

当前模板正在开发中,目前支持生成实体类、MyBatis映射、Dao、Service,更多模板近期上传,请关注更新。
欢迎各位上传自己的模板,参与协同开发。

  1. 根据数据库信息生成实体类与MyBatis映射
  2. 自动生成DAO/Service/Action/Controller/jsp/html/javascript等代码
  3. 自动识别数据库命名规则,生成规范的java名
  4. 支持自定义模板,生成任何你需要的文件格式
  5. 可根据配置支持逻辑删除、乐观锁、区间查询、模糊查询等功能
  6. 全库批量生成,一次完成所有基础代码的编写工作

使用示例

示例程序

可下载build文件夹中的jar包立即开始使用。说明文档正在编写中,近期上传。
如果觉得这个项目有用请动动小手点击右上角Star ~^_^~ Star

示例程序

生成效果

生成效果 生成文件列表

示例代码

GeneratorConfig generatorConfig = new GeneratorConfig();
generatorConfig.setAuthor("YouYuan");
generatorConfig.setPackageName("com.yuan");
generatorConfig.setOutputPath("F:/Temp/AutoGeneratorCode/Test2.0/Jar");//设置文件输出路径
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setDbUrl("jdbc:mysql://localhost:3306/generator?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true");//数据库连接地址
databaseConfig.setDbName("generator");//数据库名
databaseConfig.setUsername("youyuan");//连接数据库的用户名,此处最好使用具有root权限的用户
databaseConfig.setPassword("123");//数据库用户密码
databaseConfig.setTablePrefix("t_");//数据库表名前缀,用于生成类时自动去除此前缀
GeneratorCode generatorCode = new GeneratorCode();
generatorCode.setDatabaseConfig(databaseConfig).setGeneratorConfig(generatorConfig);//应用设置
generatorCode.batchGenerator();//全库批量生成

兼容性

JDK1.6+

支持数据库

暂只支持MySQL数据库。

数据表注释配置语法

CREATE TABLE `t_member` (
  `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID{{hidden,blank}}',
  `NAME` varchar(100) NOT NULL COMMENT '姓名{{like}}',
  `AGE` int(11) NOT NULL COMMENT '年龄{{regex:"\\d{1,2}",interval}}',
  `MONEY` decimal(12,2) DEFAULT '0.00' COMMENT '余额{{interval}}',
  `CONTENT` text COMMENT '个人详情{{like}}',
  `STATE` int(11) DEFAULT '1' COMMENT '状态{{cover:"1:启用,2:禁用"}}',
  `VERSION` int(11) DEFAULT '0' COMMENT '版本号{{b,h}}',
  `IS_DEL` int(11) DEFAULT '0' COMMENT '是否删除{{b,c:"0:否,1:是"}}',
  `SORT` int(11) DEFAULT '0' COMMENT '排序{{b}}',
  `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间{{b}}',
  `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间{{b}}',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员{{useLock,lockFiled:"VERSION",logicDel,delFiled:"IS_DEL"}}';

配置说明:

配置写在注释(comment)结尾的双大括号"{{}}"中,格式为{{配置名:"配置值"}},无配置值的只要写配置名即可。

table配置

  1. useLock:对此表的update使用乐观锁
  2. lockFiled:用于实现乐观锁的版本字段,配置值是字段名
  3. logicDel:对此表数据启用逻辑删除
  4. delFiled:用于实现逻辑删除的标记字段,配置值是字段名

命令支持简写(l=useLock,lf=lockFiled,d=logicDel,df=delFiled)

column配置

  1. hidden:字段添加到页面表单隐藏域
  2. blank:页面隐藏此字段信息
  3. regex:数据校验正则表达式
  4. interval:字段支持区间查询
  5. cover:数据值转换配置
  6. like:使用模糊查询

命令支持简写(h=hidden,b=blank,i=interval,r=regex,l=like,c=cover)

更新日志

版本:2.0(核心重构)

更新日期:2017-12-17

核心代码已完成,可以下载并参照示例运行,不过模板现在还不完整,后续会不断添加。

更新说明:

  • table的注释新增了useLock、lockFiled、logicDel、delFiled四个配置参数,用于实现乐观锁以及逻辑删除
  • column的注释新增了hidden、blank、regex、interval、cover、like六个参数,用于控制数据的查询以及显示等
  • 数据注释配置语法修改,写在注释(comment)结尾的双大括号"{{}}"中,格式为{{配置名:"配置值"}},无配置值的只要写配置名即可。(此修改不兼容1.5及以下版本)
  • 支持指定多个表生成
  • 支持设定不需要生成的表
  • 新增获取构建信息集合的接口,方便进行个性化定制需求
  • 移除了根据配置文件生成代码的功能
  • 移除了将数据表信息导出到Excel的功能(可使用构建信息集合自行灵活实现)
  • 文件生成完毕后自动打开输出路径的文件管理器
  • 模板外访问构建数据集支持链式调用,可获取的数据更多
  • 支持模板引擎语法解析占位符配置
  • 优化程序结构
  • 极大优化程序性能,经测试相比1.5版本性能提升8倍。
  • 修复已知bug

版本:1.5

更新日期:2017-10-27
更新说明:

  • 查询数据库信息时使用了极简的数据库连接池,程序运行效率提升一倍
  • 优化程序结构,提高代码生成速度
  • 模板完善
  • 完善程序运行提示

版本:1.4

更新日期:2017-10-26
更新说明:

  • 智能识别数据表列注释,读取其中的code-值映射说明,在页面可自动将代码转换为值
  • 优化程序性能,提高代码生成速度
  • 模板完善

版本:1.1

更新日期:2017-09-05
功能列表:

  1. 支持生成MySQL数据库表的实体类/MyBatis映射
  2. 自动识别数据库命名规则,生成规范的java名 (下划线分隔的单词自动转换成驼峰命名法,其它的转换首字母大小写)
  3. 自动生成DAO/Service/Manage/Action/Controller/jsp/html/javascript等代码
  4. 生成的Mapping支持根据时间区间进行查询
  5. 自动生成spring等配置文件
  6. 自动生成代码注释
  7. 生成类名时自动移除表前缀
  8. 将数据表信息导出为Excel
  9. 智能识别驱动类等信息,简化配置
  10. 全数据库批量生成代码!简单配置几个基础信息,即可将数据库所有表的模板代码生成
  11. 支持自定义模板,定制你想要的代码!

未来功能开发计划

  • 新增模板(Html、Js、Controller、Action、Service、Dao、xml等)
    • 数据更新接口支持自动实现乐观锁
    • 数据删除接口支持自动实现逻辑删除功能
    • 根据数据表配置规则,模板自动实现是否显示、区间查询等功能
    • 支持(客户端与服务端)数据根据用户设置的正则表达式自动校验
  • 支持更多的数据库
  • 更加丰富的模板支持
  • 优化代码,提升性能
  • ……
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2017 友缘 QQ:1265161633 Email:xiyousuiyuan@163.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

AutoGeneratorCode是一个代码生成引擎,可智能解析数据库信息,配合模板能够完成生成代码、编写文件等工作。已集成所有依赖包,只需导入一个jar,编写简单的配置即可使用。 支持数据库所有表的批量生成,一键自动完成所有模板代码编写工作! 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/PanXuan/AutoGeneratorCode.git
git@gitee.com:PanXuan/AutoGeneratorCode.git
PanXuan
AutoGeneratorCode
AutoGeneratorCode
master

搜索帮助