Mybatis逆向工程如何使用

Mybatis-generate 逆向工程

1. generate.xml

<?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>
	<!-- 数据库访问的驱动包 -->
	<classPathEntry location="D:\project_he\trunk\mios-chinamobile-sx-rest\mybatis-generator\lib\mysql-connector-java-5.1.29.jar" />

	<context id="MySqlTables" targetRuntime="MyBatis3">
		<property name="javaFileEncoding" value="utf-8" />
		<property name="mergeable" value="true"></property>
		<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"></plugin>
		<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
		<commentGenerator>
			<!-- 如果你只生成一次代码,以后再不用工具生成可以关闭注释,如果会重复生成就要把注释开关打开。我的配置参数是打开时间注释 -->
			<property name="suppressDate" value="false" />
			<!-- 是否去除自动生成的注释 这个最好设置成false 否则容易出现重复代码 -->
			<property name="suppressAllComments" value="false" />
		</commentGenerator>
		<!--数据库链接URL,用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://10.209.198.83:3306/emalldb" userId="emall"
			password="emall">
		</jdbcConnection>
		
		<!--javaType解析器 -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- 生成模型的包名和位置 -->
		<javaModelGenerator targetPackage="com.sitech.boss.dao.model"
			targetProject="src\main\java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- 生成映射文件的包名和位置 -->
		<sqlMapGenerator targetPackage="com.sitech.boss.dao.mapper"
			targetProject="src\main\java">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		
		<!-- 生成DAO接口的包名和位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.sitech.boss.dao.api"
			targetProject="src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
	
	
<!-- 		<table tableName="td_pcard_act_stall" domainObjectName="TdPcardActStall" enableCountByExample="false" -->
<!-- 			enableUpdateByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> -->
<!-- 			<property name="constructorBased" value="false" /> td_sign_repair_detail-->
<!-- 		</table> -->
		<table tableName="all_prod_operate_log" domainObjectName="AllProdOperateLog" enableCountByExample="true"
		enableUpdateByExample="true"  enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
			<property name="constructorBased" value="false" />
		</table>
<!-- 		<table tableName="td_pcard_act" domainObjectName="TdPcardAct" enableCountByExample="false" -->
<!-- 		enableUpdateByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> -->
<!-- 			<property name="constructorBased" value="false" /> -->
<!-- 		</table> -->

	</context>
</generatorConfiguration>

 

2.Maven配置

 

 

<plugins>

    <plugin>

        <groupId>org.mybatis.generator</groupId>

        <artifactId>mybatis-generator-maven-plugin</artifactId>

        <version>1.3.2</version><!--$NO-MVN-MAN-VER$ -->

        <configuration>

            <configurationFile>${project.basedir}/mybatis-generator/generatorConfig.xml</configurationFile>

            <verbose>true</verbose>

            <overwrite>true</overwrite>

            <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>

            <jdbcURL>jdbc:mysql://172.18.231.39:3317/hesxdb</jdbcURL>

            <jdbcUserId>hesxdb</jdbcUserId>

            <jdbcPassword>hesxdb</jdbcPassword>

        </configuration>

        <executions>

            <execution>

                <id>Generate MyBatis Artifacts</id>

                <goals>

                    <goal>generate</goal>

                </goals>

            </execution>

        </executions>

        <dependencies>

            <dependency>

                <groupId>org.mybatis.generator</groupId>

                <artifactId>mybatis-generator-core</artifactId>

                <version>1.3.2</version>

            </dependency>

        </dependencies>

    </plugin>

    </plugins>

 

       3. 使用方式

 

     ①在Eclipse 中:找到mybatis-generator文件夹->右键Run As->Run Configurations->Maven Build->New Configuration->Base directory->复制粘贴-X clean        mybatis-generator:generate。 !记得在base directory 指向当前项目(亲身采坑)

     ②在IDEA 中使用maven插件

点击MavenProject->plugins 中的   mybatis-generate

 

 

      


     

      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值