MyBatis逆向工程生成—STS实现


MyBatis逆向工程生成—STS实现


1、下载MyBatis-generator 插件

mybatis1

mybatis2

2、http://mybatis.org/generator/configreference/xmlconfig.html查找mybatis逆向工程的配置文件

<?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="/Program Files/IBM/SQLLIB/java/db2java.zip" />

  <context id="DB2Tables" targetRuntime="MyBatis3">
    <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
        connectionURL="jdbc:db2:TEST"
        userId="db2admin"
        password="db2admin">
    </jdbcConnection>

    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <javaModelGenerator targetPackage="test.model" targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="test.xml"  targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

    <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

    <table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
      <property name="useActualColumnNames" value="true"/>
      <generatedKey column="ID" sqlStatement="DB2" identity="true" />
      <columnOverride column="DATE_FIELD" property="startDate" />
      <ignoreColumn column="FRED" />
      <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
    </table>

  </context>
</generatorConfiguration>

3、在resources目录下新建generatorConfig.xml文件,并修改相关配置

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RUfqpWyo-1636038311384)(http://qiliu.luxiaobai.cn/img/mybatis3.png)]

<?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="/opt/apache-maven-3.6.2/repository/mysql/mysql-connector-java/8.0.25/mysql-connector-java-8.0.25-sources.jar" />

	<context id="DB2Tables" targetRuntime="MyBatis3">
		<!-- 不生成注释 -->
		<commentGenerator>
			<property name="suppressDate" value="true" />
			<property name="suppressAllComments" value="true" />
		</commentGenerator>

		<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/WEBCHAT?useSSL=false" userId="root"
			password="Sal123456">
		</jdbcConnection>

		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<javaModelGenerator
			targetPackage="com.luxiaobai.web_chat.pojo"
			targetProject="WebChat/src/main/java" />

		<!-- xxxMapper.xml -->
		<sqlMapGenerator targetPackage="com.luxiaobai.mapper"
			targetProject="WebChat/src/main/resources" />

		<!-- mapper接口位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.luxiaobai.web_chat.mapper" targetProject="WebChat/src/main/java" />

		<!-- 实体类 -->
		<table tableName="chat_msg" domainObjectName="ChatMsg"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"></table>
		<table tableName="friends_request"
			domainObjectName="FriendsRequest" enableCountByExample="false"
			enableSelectByExample="false" enableDeleteByExample="false"
			enableUpdateByExample="false"></table>
		<table tableName="my_friends" domainObjectName="MyFriends"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"></table>
		<table tableName="t_users" domainObjectName="User"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"></table>

	</context>
</generatorConfiguration>

4、在pom.xml文件中引入逆向工程文件的插件

<dependency>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-maven-plugin</artifactId>
			<version>1.3.2</version>
		</dependency>
  
  <plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.2</version>
			</plugin>

5、在generatorConfig.xml右键Run AS运行即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路小白&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值