1 Star 11 Fork 9

Mirren / screw-driver

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

起步

ScrewDriver是一个用于生成代码、创建或读取数据库表信息的工具包,该工具想达到的目的是藉着IDE的代码块,通过快捷键快速生成代码,或成为其他生成工具的基础工具!

使用帮助

使用文档: http://mirren.gitee.io/screw-driver-docs

运行环境要求: java >= 1.6

QQ交流群:519714660 加入QQ交流群

在B站中查看基本使用教程视频

添加依赖

<dependency>
    <groupId>org.mirrentools</groupId>
    <artifactId>screw-driver</artifactId>
    <version>[1.0.0,2.0.0)</version>
</dependency>

读取数据库表信息并生成代码示例

  1. 初始化ScrewDriver
  2. 读取表信息并执行创建
public static void main(String[] args) throws Exception {
	// 初始化执行工具
	ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions(databaseOptions));
	// 读取表信息
	SdClassContent content = screwDriver.readTable("root");
	// 创建代码
	screwDriver.createCode(content,templates);
}

仅创建代码示例

  1. 定义 SdBean
  2. 初始化ScrewDriver并执行
public static void main(String[] args) throws Exception {
	// 创建一个实体描述
	SdBean bean = new SdBean();
	bean.setName("user").setRemark("用户");
	bean.addColumn(new SdColumn().setName("id").setType(SdType.LONG).setPrimary(true).setRemark("用户的id"));
	bean.addColumn(new SdColumn().setName("name").setType(SdType.STRING).setLength(30).setRemark("用户的名字"));
	bean.addColumn(new SdColumn().setName("pwd").setType(SdType.STRING).setLength(60).setRemark("用户的的密码"));
	
	// 初始化执行工具
	ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions());
	// 创建代码
	screwDriver.createCode(bean,templates);
}

创建代码与生成表示例

  1. 定义 SdBean
  2. 初始化 ScrewDriver 并执行创建
public static void main(String[] args) throws Exception {
	// 创建一个实体描述
	SdBean bean = new SdBean();
	bean.setName("user").setRemark("用户");
	bean.addColumn(new SdColumn().setName("id").setType(SdType.LONG).setPrimary(true).setRemark("用户的id"));
	bean.addColumn(new SdColumn().setName("name").setType(SdType.STRING).setLength(30).setRemark("用户的名字"));
	bean.addColumn(new SdColumn().setName("pwd").setType(SdType.STRING).setLength(60).setRemark("用户的的密码"));

	// 初始化执行工具
	ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions(databaseOptions));
	// 创建代码
	screwDriver.createCode(bean,templates);
	// 生成表
	screwDriver.createTable(bean);
}

templates与databaseOptions示例

	// 设置实体生成模板
	Map<String, SdTemplate> templates = new HashMap<String, SdTemplate>();
	templates.put("entity", new SdTemplate().setFile("JavaEntity.ftl").setPackageName("entity").setClassName("User"));
	templates.put("dao", new SdTemplate().setFile("Dao.ftl").setPackageName("dao").setClassName("Dao"));
	templates.put("service", new SdTemplate().setFile("Service.ftl").setPackageName("service").setClassName("Service"));
	templates.put("controller", new SdTemplate().setFile("Controller.ftl").setPackageName("controller").setClassName("Controller"));
	
	// 初始化数据库连接信息
	SdDatabaseOptions databaseOptions = new SdDatabaseOptions(MySQL.MYSQL_8_DERVER, "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&serverTimezone=UTC");
	databaseOptions.setUser("root");
	databaseOptions.setPassword("root");
MIT License Copyright (c) 2019 MirrenTools Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

ScrewDriver是一个用于生成代码、创建或读取数据库表信息的工具包,该工具想达到的目的是藉着IDE的代码块,通过快捷键快速生成代码,或成为其他生成工具的基础库! expand collapse
Java and 3 more languages
MIT
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
Java
1
https://gitee.com/mirren/screw-driver.git
git@gitee.com:mirren/screw-driver.git
mirren
screw-driver
screw-driver
master

Search

53164aa7 5694891 3bd8fe86 5694891