Commit 3d0fa9b1 authored by 孙长纪's avatar 孙长纪

增加详细描述

parent b87ed3d8
......@@ -14,40 +14,34 @@ testCompile("cn.com.duiba:mysql-generator")
```
在test目录下新建CodeGeneratorTest.java,代码如下
```java
public class MysqlGeneratorTest {
private static final String DB_URL_TPL = "jdbc:mysql://dev.config.duibar.com:3306/{0}?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000";
/**
* 库名
/**
* 根据数据库表生成代码
*/
public class MysqlGeneratorTest {
//库名
private static final String TABLE_SCHEMA = "act_com_conf";
/**
* 表名
*/
//表名
private static final String TABLE_NAME = "tb_duiba_brick_config";
//生成entity代码位置
private static final String ENTITY_PACKAGE = "cn.com.duiba.activity.center.biz.test.entity";
//生成dao代码位置
private static final String DAO_PACKAGE = "cn.com.duiba.activity.center.biz.test.dao";
//mapper.xml文件位置,需要加上所在的模块名称下位置,比如activity-center-deploy模块下src/main/resources/mybatis/test目录下
private static final String XML_LOCATION = "activity-center-deploy/src/main/resources/mybatis/test";
/**
* 数据库账户
*/
private static final String USER = "dev";
/**
* 数据库密码
*/
private static final String PWD = "dev_fas015";
private static final String DB_URL_TPL = "jdbc:mysql://dev.config.duibar.com:3306/{0}?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000";
@Test
public void createCode(){
String DB_URL = MessageFormat.format(DB_URL_TPL,TABLE_SCHEMA);
GeneratorConfig config = new GeneratorConfig(DB_URL, USER, PWD);
//生成dao代码位置
config.setDaoPackage("cn.com.duiba.test.dao");
public void generateCode(){
String DB_URL = MessageFormat.format(DB_URL_TPL, TABLE_SCHEMA);
GeneratorConfig config = new GeneratorConfig(DB_URL, "dev", "dev_fas015");
//生成entity代码位置
config.setEntityPackage("cn.com.duiba.test.entity");
//mapper.xml文件位置
config.setXmlLocation("src/main/resources/mybatis/test");
config.setEntityPackage(ENTITY_PACKAGE);
config.setTestExe(false);
//生成dao代码位置
config.setDaoPackage(DAO_PACKAGE);
//mapper.xml文件位置,以测试用例的方式启动则
config.setXmlLocation(XML_LOCATION);
//数据库名
config.setTableSchema(TABLE_SCHEMA);
//表名
......@@ -57,7 +51,7 @@ public class MysqlGeneratorTest {
//设置生成的java文件存放的模块名,如果该代码执行和生成的代码在一个模块下则不需要设置,
//比如该执行代码在activity-center-deploy模块下,需要生成的entity,dao,daoImpl需要在activity-center-biz模块下,则需要设置ModuleName的值为activity-center-biz
//如果该执行代码在activity-center-biz下,并且生成的代码也在activity-center-biz下则不需要设置ModuleName的值
config.setModuleName("");
config.setModuleName("activity-center-biz");
MybatisGenerator.genCode(config);
}
......
......@@ -18,7 +18,7 @@ apply plugin: "idea"
apply plugin: "eclipse"
group = "cn.com.duiba"
version = "0.1.0"
version = "0.1.1"
sourceCompatibility = 1.8
targetCompatibility = 1.8
......
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="mysql-generator" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="cn.com.duiba" external.system.module.version="0.0.1" type="JAVA_MODULE" version="4">
<module external.linked.project.id="mysql-generator" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="cn.com.duiba" external.system.module.version="0.1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
......
......@@ -51,6 +51,11 @@ public class GeneratorConfig {
*/
private String moduleName;
/**
* true:以测试用例执行生成代码的方式
*/
private boolean exeTest = false;
public GeneratorConfig(String dbUrl, String dbUserName, String dbPasswd) {
this.connection = MybatisGenerator.getConnection(dbUrl, dbUserName, dbPasswd);
}
......@@ -136,4 +141,12 @@ public class GeneratorConfig {
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public boolean isExeTest() {
return exeTest;
}
public void setExeTest(boolean exeTest) {
this.exeTest = exeTest;
}
}
......@@ -28,8 +28,16 @@ public class PathUtils {
if (StringUtils.isEmpty(config.getModuleName())) {
return "src/main/java/" + StringUtils.replace(packageName, ".", "/");
}
String filePath = config.getModuleName() + File.separator + "src/main/java/" + StringUtils.replace(packageName, ".", "/");
//以main方法执行
if (config.isExeTest()) {
//以测试用例的方式执行
String modulePath = getProjectHome();
String bathPath = modulePath.substring(0,modulePath.lastIndexOf(File.separator));
return bathPath+File.separator+config.getModuleName() + File.separator + "src/main/java/" + StringUtils.replace(packageName, ".", "/");
String bathPath = modulePath.substring(0, modulePath.lastIndexOf(File.separator));
return bathPath + File.separator + filePath;
}
return filePath;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment