Java:Mybatis-generator使用

配置生成实体、Mapper等

以下是一个配置文件:

<generatorConfiguration>
	<context id="DB2Tables" targetRuntime="MyBatis3">
		<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/dump" userId="root"
			password="sa">
		</jdbcConnection>

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

		<javaModelGenerator targetPackage="com.riguz.db.dump.model"
			targetProject="src\main\java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<sqlMapGenerator targetPackage="dump.xml"
			targetProject="resource">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.riguz.db.dump.mapper" targetProject="src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>

		<table tableName="xxx"></table>
                .....
	</context>
</generatorConfiguration>

自定义SQL

使用生成的Mapper