Mybatis Generator

安装插件

步骤:help -- Eclipse Marketplace

配置

SqlServer

新建配置文件 generatorConfig.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>
	<!--配置 sqlserver jar包路径 -->
	<classPathEntry
		location="E://cps-service//lib//sqljdbc42.jar" />

	<context id="bingniterId" targetRuntime="MyBatis3">

		<!--<commentGenerator> <!– 去除自动生成的注释 –> <property name="suppressAllComments" 
			value="true" /> </commentGenerator> -->
		<!-- 是否生成注释 去除自动生成的注释 -->
		<commentGenerator>
			<property name="suppressDate" value="true" />

			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!-- 数据库连接配置 -->
		<jdbcConnection
			driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
			connectionURL="jdbc:sqlserver://10.1.10.99:1433;DatabaseName=bingniter"
			userId="sa" password="!QAZ2wsx" />

		<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制 -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!--配置生成的实体包 targetPackage:实体类包路径,默认存放在src目录下; targetProject:目标工程名 -->
		<javaModelGenerator
			targetPackage="com.bingniter.entity" targetProject="项目名字 或者 src/main/java" />

		<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
		<sqlMapGenerator targetPackage="com.bingniter.mapper"
			targetProject="learn" />
		<!--生成Dao类存放位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.bingniter.dao" targetProject="项目名字 或者 src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!--生成对应表及类名 -->
		<!-- 配置表 schema:不用填写 tableName: 表名 enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId: 
			去除自动生成的例子 -->
		<table schema="" tableName="finance_synchronization"
			domainObjectName="financeSynchronization"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"
			selectByExampleQueryId="false">
		</table>
		<!-- 可使用多个表进行生成 -->
		<table schema="" tableName="finance_adjustment"
			domainObjectName="financeAdjustment"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"
			selectByExampleQueryId="false">
		</table>

	</context>
</generatorConfiguration>

Mysql

新建配置文件 generatorConfig.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>

	<context id="bingniterId" targetRuntime="MyBatis3">
		<!-- 生成mysql带有分页的sql的插件 自己配置 -->
        <plugin type="generator.MysqlPaginationPlugin" />
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />

		<!-- 是否生成注释 去除自动生成的注释 -->
		<commentGenerator>
			<property name="suppressDate" value="true" />

			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!-- 数据库连接配置 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:sqlserver://10.1.10.99:1433;DatabaseName=bingniter"
			userId="sa" password="!QAZ2wsx" />

		<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制 -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!--配置生成的实体包 targetPackage:实体类包路径,默认存放在src目录下; targetProject:目标工程名 -->
		<javaModelGenerator
			targetPackage="com.bingniter.entity"
			targetProject="项目名字 或者 src/main/java" />

		<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
		<sqlMapGenerator targetPackage="com.bingniter.mapper"
			targetProject="learn" />
		<!--生成Dao类存放位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.bingniter.dao"
			targetProject="项目名字 或者 src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!--生成对应表及类名 -->
		<!-- 配置表 schema:不用填写 tableName: 表名 enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId: 
			去除自动生成的例子 -->
		<table schema="" tableName="finance_synchronization"
			domainObjectName="financeSynchronization"
			enableCountByExample="false" enableSelectByExample="false"
			enableDeleteByExample="false" enableUpdateByExample="false"
			selectByExampleQueryId="false">
		</table>
		<!-- 可使用多个表进行生成 -->
		<table schema="" tableName="finance_adjustment"
			domainObjectName="financeAdjustment" enableCountByExample="false"
			enableSelectByExample="false" enableDeleteByExample="false"
			enableUpdateByExample="false" selectByExampleQueryId="false">
		</table>

	</context>
</generatorConfiguration>

运行

右键点击 generatorConfig.xml - Run Mybatis Generato
------------------------------------------------------------------------------------------
MyBatis Generator Started...
Buildfile: E:\cps-workSpace\.metadata\.plugins\org.mybatis.generator.eclipse.ui\.generatedAntScripts\learn-generatorConfig.xml (1).xml
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
BUILD SUCCESSFUL
MyBatis Generator Finished
posted @ 2020-10-17 00:39  BingNiTer  阅读(163)  评论(0编辑  收藏  举报