测试修改mybatis-generator-extend插件
This commit is contained in:
+9
-15
@@ -31,25 +31,19 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<!--maven-plugin插件开发依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0.6</version>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dependencies to annotations -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
-5
@@ -2,8 +2,6 @@ package com.micro.fast.mybatis.generator.extend.db;
|
||||
|
||||
|
||||
import com.micro.fast.mybatis.generator.extend.util.PropertiesUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@@ -11,7 +9,6 @@ import java.sql.SQLException;
|
||||
|
||||
|
||||
public class JdbcConnection {
|
||||
private static final Logger log = LoggerFactory.getLogger(JdbcConnection.class);
|
||||
private static Connection connection = null;
|
||||
//加载数据库驱动获取连接
|
||||
static {
|
||||
@@ -22,10 +19,8 @@ public class JdbcConnection {
|
||||
, PropertiesUtil.getProperty("db.username"),
|
||||
PropertiesUtil.getProperty("db.password"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("错误{} {}",e,"jdbc驱动加载失败");
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
log.error("错误{} {}",e,"数据库连接失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
+17
-7
@@ -1,18 +1,28 @@
|
||||
package com.micro.fast.mybatis.generator.extend.mojo;
|
||||
|
||||
import com.micro.fast.mybatis.generator.extend.service.MybatisGeneratorExtend;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
|
||||
/**
|
||||
* maven插件执行主类
|
||||
*/
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Mojo(name = "generateFiles")
|
||||
public class MyabtisGeneratorExtendMojo extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
MybatisGeneratorExtend.GenerateMybatisGeneratorNeedFilesByTemplates();
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
Map pluginContext = getPluginContext();
|
||||
Set set = pluginContext.entrySet();
|
||||
Iterator iterator = set.iterator();
|
||||
while (iterator.hasNext()){
|
||||
Object next = iterator.next();
|
||||
System.out.println("---++++++++++++++++++++"+next);
|
||||
System.out.println(pluginContext.get(next)+"++++++++++++++++++++++++");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-6
@@ -5,8 +5,6 @@ import com.micro.fast.mybatis.generator.extend.pojo.Db;
|
||||
import com.micro.fast.mybatis.generator.extend.pojo.MybatisGenerator;
|
||||
import com.micro.fast.mybatis.generator.extend.util.FreemarkerUtil;
|
||||
import com.micro.fast.mybatis.generator.extend.util.PropertiesUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
@@ -19,7 +17,6 @@ import java.util.Map;
|
||||
* mybatis-generate-extend-maven-plugin主要逻辑
|
||||
*/
|
||||
public class MybatisGeneratorExtend {
|
||||
private static final Logger log = LoggerFactory.getLogger(MybatisGeneratorExtend.class);
|
||||
|
||||
private static Db db;
|
||||
|
||||
@@ -27,8 +24,14 @@ public class MybatisGeneratorExtend {
|
||||
|
||||
//初始化参数
|
||||
static {
|
||||
if (db==null){
|
||||
db = new Db();
|
||||
}
|
||||
if (mybatisGenerator==null){
|
||||
mybatisGenerator = new MybatisGenerator();
|
||||
}
|
||||
MybatisGeneratorExtend.db.setDriverLocation(PropertiesUtil.getProperty("db.driverLocation"));
|
||||
MybatisGeneratorExtend.db.setUrl(PropertiesUtil.getProperty("db.url"));
|
||||
MybatisGeneratorExtend.db.setUrl(PropertiesUtil.getProperty("db.url").replaceAll("&","&"));
|
||||
MybatisGeneratorExtend.db.setUsername(PropertiesUtil.getProperty("db.username"));
|
||||
MybatisGeneratorExtend.db.setPassword(PropertiesUtil.getProperty("db.password"));
|
||||
MybatisGeneratorExtend.db.setDriverClassName(PropertiesUtil.getProperty("db.driverClassName"));
|
||||
@@ -57,7 +60,7 @@ public class MybatisGeneratorExtend {
|
||||
while (resultSet.next()) {
|
||||
String tableName = resultSet.getString(1);
|
||||
if (tableName.startsWith(mybatisGenerator.getTablesPrefix())) {
|
||||
String doMainObjectName = null;
|
||||
String doMainObjectName = "";
|
||||
String[] strings = tableName.split("_");
|
||||
for (String string : strings) {
|
||||
char c = string.charAt(0);
|
||||
@@ -77,7 +80,6 @@ public class MybatisGeneratorExtend {
|
||||
boolean mybatisGeneratorFileSuccess = FreemarkerUtil.createFile("mybatisGenerator.ftl", mybatisGeneratorModel, "mybatisGenerator.properties");
|
||||
boolean generatorConfigFileSuccess = FreemarkerUtil.createFile("generatorConfig.ftl", mybatisGeneratorModel, "generatorConfig.xml");
|
||||
} catch (SQLException e) {
|
||||
log.error("错误{} {}", e, "sql语句执行失败");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
//3.关闭流
|
||||
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package com.micro.fast.mybatis.generator.extend.util;
|
||||
|
||||
import com.micro.fast.mybatis.generator.extend.service.MybatisGeneratorExtend;
|
||||
import freemarker.core.ParseException;
|
||||
import freemarker.template.*;
|
||||
|
||||
@@ -132,5 +133,6 @@ public class FreemarkerUtil {
|
||||
System.out.println(System.getProperty("user.dir"));
|
||||
//5.获取所有的类的jar的加载路径
|
||||
System.out.println(System.getProperty("java.class.path"));
|
||||
MybatisGeneratorExtend.GenerateMybatisGeneratorNeedFilesByTemplates();
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -1,13 +1,9 @@
|
||||
package com.micro.fast.mybatis.generator.extend.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PropertiesUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(Properties.class);
|
||||
private static final String PROPERTIES_PATH = "mybatisStart.properties";
|
||||
private static Properties properties = null;
|
||||
static {
|
||||
@@ -20,7 +16,6 @@ public class PropertiesUtil {
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error("错误{} {}",e,"未找到mybatisStart.properties配置文件");
|
||||
e.printStackTrace();
|
||||
}
|
||||
//3.将输入流写入到properties对象中
|
||||
@@ -30,7 +25,6 @@ public class PropertiesUtil {
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
log.error("错误{} {}",e,"mybatisStart.properties配置文件失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
|
||||
<!--指定特定数据库的jdbc驱动jar包的位置-->
|
||||
<classPathEntry location="/root/mysql-connector-java-5.1.40-bin.jar"/>
|
||||
|
||||
<context id="default" targetRuntime="MyBatis3" defaultModelType="flat">
|
||||
<!--java文件的编码设置-->
|
||||
<property name="javaFileEncoding" value="UTF-8"/>
|
||||
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号("),在Mysql中不能这么写,所以还要将这两个默认值改为` -->
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
<!-- 为生成的Java模型创建一个toString方法 -->
|
||||
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
|
||||
<!-- 对生成的pojo集成serializable接口-->
|
||||
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" ></plugin>
|
||||
<!-- optional,旨在创建class时,对注释进行控制 -->
|
||||
<commentGenerator>
|
||||
<property name="suppressDate" value="true"/>
|
||||
<property name="suppressAllComments" value="true"/>
|
||||
</commentGenerator>
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection
|
||||
driverClass="com.mysql.jdbc.Driver"
|
||||
connectionURL="jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false"
|
||||
userId="root"
|
||||
password="studyj2e">
|
||||
</jdbcConnection>
|
||||
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
|
||||
<javaTypeResolver>
|
||||
<property name="forceBigDecimals" value="false"/>
|
||||
</javaTypeResolver>
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径
|
||||
-->
|
||||
<javaModelGenerator targetPackage="pojoPackage" targetProject="./src/main/java">
|
||||
<!-- 是否允许子包,即targetPackage.schemaName.tableName -->
|
||||
<property name="enableSubPackages" value="false"/>
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 是否对类CHAR类型的列的数据进行trim操作 -->
|
||||
<property name="trimStrings" value="true"/>
|
||||
<!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
|
||||
<property name="immutable" value="false"/>
|
||||
</javaModelGenerator>
|
||||
|
||||
<!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
|
||||
<sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
|
||||
<property name="enableSubPackages" value="false"/>
|
||||
</sqlMapGenerator>
|
||||
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
|
||||
-->
|
||||
|
||||
<!-- targetPackage:mapper接口dao生成的位置 -->
|
||||
<!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
|
||||
<javaClientGenerator type="XMLMAPPER" targetPackage="daoPackage" targetProject="./src/main/java" >
|
||||
<!-- enableSubPackages:是否让schema作为包的后缀 -->
|
||||
<property name="enableSubPackages" value="false" />
|
||||
</javaClientGenerator>
|
||||
<table tableName="upms_user_role" domainObjectName="UpmsUserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_log" domainObjectName="UpmsLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_system" domainObjectName="UpmsSystem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_organization" domainObjectName="UpmsOrganization" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_role_permission" domainObjectName="UpmsRolePermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_permission" domainObjectName="UpmsPermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_user" domainObjectName="UpmsUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_user_organization" domainObjectName="UpmsUserOrganization" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_role" domainObjectName="UpmsRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="upms_user_permission" domainObjectName="UpmsUserPermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
db.driverLocation=/root/mysql-connector-java-5.1.40-bin.jar
|
||||
db.driverClassName=com.mysql.jdbc.Driver
|
||||
db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false
|
||||
db.username=root
|
||||
db.password=studyj2e
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
#mybatisGeneratorExtend所需要的参数
|
||||
db.driverLocation=
|
||||
db.driverClassName=
|
||||
db.url=
|
||||
db.username=
|
||||
db.password=
|
||||
mybatisGenerator.pojoPackage=
|
||||
mybatisGenerator.daoPackage=
|
||||
mybatisGenerator.tablesPrefix=
|
||||
#mybatisGeneratorExtend\u6240\u9700\u8981\u7684\u53C2\u6570
|
||||
db.driverLocation=/root/mysql-connector-java-5.1.40-bin.jar
|
||||
db.driverClassName=com.mysql.jdbc.Driver
|
||||
db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false
|
||||
db.username=root
|
||||
db.password=studyj2e
|
||||
mybatisGenerator.pojoPackage=pojoPackage
|
||||
mybatisGenerator.daoPackage=daoPackage
|
||||
mybatisGenerator.tablesPrefix=upms
|
||||
+3
-3
@@ -26,8 +26,8 @@
|
||||
<jdbcConnection
|
||||
driverClass="${db.driverClassName}"
|
||||
connectionURL="${db.url}"
|
||||
userId="${db.url}"
|
||||
password="{db.passworld}">
|
||||
userId="${db.username}"
|
||||
password="${db.password}">
|
||||
</jdbcConnection>
|
||||
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
|
||||
<javaTypeResolver>
|
||||
@@ -67,7 +67,7 @@
|
||||
<property name="enableSubPackages" value="false" />
|
||||
</javaClientGenerator>
|
||||
<#list mybatisGenerator.tablesNameAndDoMainObjectsName?keys as key >
|
||||
<table tableName="${key}" domainObjectName="${mybatisGenerator.tablesNameAndDoMainObjectsName.get(key)}" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
<table tableName="${key}" domainObjectName="${mybatisGenerator.tablesNameAndDoMainObjectsName["${key}"]}" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
|
||||
</#list>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
db.driverLocation=${db.driverLocation}
|
||||
db.driverClassName=${db.driverClassName}
|
||||
db.url=${db.url}
|
||||
db.username=${db.url}
|
||||
db.password=${db.passworld}
|
||||
db.username=${db.username}
|
||||
db.password=${db.password}
|
||||
@@ -109,6 +109,11 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.micro.fast</groupId>
|
||||
<artifactId>mybatis-generator-extend-maven-plugin</artifactId>
|
||||
<version>${micro.fast.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#mybatisGeneratorExtend\u6240\u9700\u8981\u7684\u53C2\u6570
|
||||
db.driverLocation=/root/mysql-connector-java-5.1.40-bin.jar
|
||||
db.driverClassName=com.mysql.jdbc.Driver
|
||||
db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false
|
||||
db.username=root
|
||||
db.password=studyj2e
|
||||
mybatisGenerator.pojoPackage=pojoPackage
|
||||
mybatisGenerator.daoPackage=daoPackage
|
||||
mybatisGenerator.tablesPrefix=upms
|
||||
Reference in New Issue
Block a user