IDEA使用mybatisgenerator自动生成代码
博客专区 > yejunwei 的博客 > 博客详情
IDEA使用mybatisgenerator自动生成代码
yejunwei 发表于8个月前
IDEA使用mybatisgenerator自动生成代码
  • 发表于 8个月前
  • 阅读 10
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

结构目录如下:

pom文件配置:

由于使用了分页插件,所以要先把分页插件用maven 打成jar包,再依赖进去

<!--MG的插件-->
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.3</version>
				<configuration>
					<!--指定mg的配置文件的位置,默认情况不是在类加载目录下的,我这里设置在test目录下-->
					<configurationFile>src/test/resources/ProjectMgrGeneConfig.xml</configurationFile>
					<verbose>true</verbose>
					<overwrite>true</overwrite>
				</configuration>
				<dependencies>
					<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java
            配置这个依赖主要是为了等下在配置MG的时候可以不用配置classPathEntry这样的一个属性,避免
            代码的耦合度太高 -->
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>${mysql.version}</version>
					</dependency>
					<!--这里引用分页插件,因为这个分页插件是自己写的,所以需要先用maven打成jar包,再在这里配置
					在配置文件中有使用到,所以必须要引入-->
					<dependency>
						<groupId>cn.com.bsfit</groupId>
						<artifactId>generator.plugin</artifactId>
						<version>2.0.0</version>
					</dependency>
				</dependencies>
			</plugin>
<!--MG的插件-->
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.3</version>
				<configuration>
					<!--指定mg的配置文件的位置,默认情况不是在类加载目录下的,我这里设置在test目录下-->
					<configurationFile>src/test/resources/ProjectMgrGeneConfig.xml</configurationFile>
					<verbose>true</verbose>
					<overwrite>true</overwrite>
				</configuration>
				<dependencies>
					<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java
            配置这个依赖主要是为了等下在配置MG的时候可以不用配置classPathEntry这样的一个属性,避免
            代码的耦合度太高 -->
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>${mysql.version}</version>
					</dependency>
					<!--这里引用分页插件,因为在配置文件中要使用到,必须要引入-->
					<dependency>
						<groupId>cn.com.bsfit</groupId>
						<artifactId>generator.plugin</artifactId>
						<version>2.0.0</version>
					</dependency>
				</dependencies>
			</plugin>

mg的配置文件

<?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>

    <!--<properties resource="/src/test/resources/ProjectMgrGeneConfig.properties" />-->
    <!--<properties resource="/src/test/resources/ProjectMgrGeneConfig.properties" />-->
    <!--<classPathEntry location="C:\\maven\\repository\\mysql\\mysql-connector-java\\5.1.35\\mysql-connector-java-5.1.35.jar" />-->

    <context id="frms-pm" targetRuntime="MyBatis3">
    	<property name="javaFileEncoding" value="UTF-8"/>
        <plugin type="mysql.PaginationPlugin"  />
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
        <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
        <commentGenerator type="mysql.CommentPlugin">
            <property name="suppressDate" value="true" />
            <!--去除自动生成注释 --> 
            <property name="suppressAllComments" value="false" />
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://10.100.1.85:3306/frms-mt-mgr2.0" userId="root" password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <javaModelGenerator targetProject="C:\Users\Think\Documents\多租户2.0\multi-tenancy\bsfit-mt-center\frms-mt-mgr-base\src\main\java" targetPackage="cn.com.bsfit.frms.portal.base.pojo" >
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetProject="C:\Users\Think\Documents\多租户2.0\multi-tenancy\bsfit-mt-center\frms-mt-mgr-base\src\main\resources" targetPackage="mysql.cn.com.bsfit.frms.portal.base.sqlmap" >
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetProject="C:\Users\Think\Documents\多租户2.0\multi-tenancy\bsfit-mt-center\frms-mt-mgr-base\src\main\java" targetPackage="cn.com.bsfit.frms.portal.base.mapper">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        
        <!-- ========================多租户2.0表格======================== -->
<!--          <table schema="frms-mt-mgr2.0" tableName="mt_tenancy" domainObjectName="MTTenancy"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--         <table schema="frms-mt-mgr2.0" tableName="mt_role" domainObjectName="MTRole"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--         <table schema="frms-mt-mgr2.0" tableName="mt_user" domainObjectName="MTUser"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--           <table schema="frms-mt-mgr2.0" tableName="mt_engine" domainObjectName="MTEngine"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--             <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--          <table schema="frms-mt-mgr2.0" tableName="server" domainObjectName="Server"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--             <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--       <table schema="frms-mt-mgr2.0" tableName="logs" domainObjectName="Logs"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
<!--         ========================多租户2.0表格========================      -->
 		<!-- ========================多租户2.1新增表格======================== --> 
<!-- 		 <table schema="frms-mt-mgr2.0" tableName="engine_version" domainObjectName="EngineVersion"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--             <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--          <table schema="frms-mt-mgr2.0" tableName="engine_version_log" domainObjectName="EngineVersionLog"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--             <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
         <!--<table schema="frms-mt-mgr2.0" tableName="engine_config" domainObjectName="EngineConfig">-->
             <!--<property name="constructorBased" value="true" />-->
             <!--<property name="useActualColumnNames" value="false" />-->
             <!--<property name="ignoreQualifiersAtRuntime" value="true" />-->
             <!--<generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/>-->
         <!--</table>-->
        
<!--        <table schema="frms-mt-mgr2.0" tableName="probe" domainObjectName="Probe"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
        <!--<table schema="frms-mt-mgr2.0" tableName="streamcube" domainObjectName="Streamcube">-->
            <!--<property name="useActualColumnNames" value="false" />-->
            <!--<property name="ignoreQualifiersAtRuntime" value="true" />-->
            <!--<generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/>-->
        <!--</table>-->
        
        <table schema="frms-mt-mgr2.0" tableName="streamcube_config" domainObjectName="StreamcubeConfig">
             <property name="constructorBased" value="true" />
             <property name="useActualColumnNames" value="false" />
             <property name="ignoreQualifiersAtRuntime" value="true" />
              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/>
         </table>
        
<!--           <table schema="frms-mt-mgr2.0" tableName="tenancy_streamcube" domainObjectName="TenancyStreamcube"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" />  -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
        
<!--         <table schema="frms-mt-mgr2.0" tableName="streamcube_group" domainObjectName="StreamcubeGroup"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table> -->
   
<!--    		<table schema="frms-mt-mgr2.0" tableName="mt_api_count" domainObjectName="MTApiCount"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--         </table>  -->
        
<!--         <table schema="frms-mt-mgr2.0" tableName="tenant_auth_info" domainObjectName="TenantAuthInfo"> -->
<!--             <property name="constructorBased" value="true" /> -->
<!--             <property name="useActualColumnNames" value="false" /> -->
<!--             <property name="ignoreQualifiersAtRuntime" value="true" /> -->
<!--              <generatedKey column="ID" sqlStatement="MySql" identity="true" type="post"/> -->
<!--         </table>  -->
		<!-- ========================多租户2.1新增表格======================== -->
    </context>
</generatorConfiguration>

 

共有 人打赏支持
粉丝 0
博文 36
码字总数 7565
×
yejunwei
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: