MyBatis逆向工程

本文详细介绍如何使用MyBatis Generator生成持久层代码,包括配置文件的设置、数据库连接信息及生成的Java模型、Mapper映射文件等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

逆向工程文件

  • 依赖
<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
    </configuration>
</plugin>
  • 配置文件
<?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>
	<!-- 连接mysql驱动包所在位置 -->
	<classPathEntry location="F:\WorkSoft\LocalRepository\mysql\mysql-connector-java\5.1.43\mysql-connector-java-5.1.43.jar" />
	<context id="db2tables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!--是否去除自动生成的注释 true是,false否-->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!-- 数据库连接信息,驱动类、连接地址、用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://10.31.152.25:3306/xfkuaidi" userId="fanxiongfeng"
			password="123456">
		</jdbcConnection>
		<!--<jdbcConnection driverClass="oracle.jdbc.OracleDriver"-->
						<!--connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="scott"-->
						<!--password="tigger">-->
		<!--</jdbcConnection>-->

		<!--默认false,把JDBC DECIMAL和NUMBERIC类型解析为Integer-->
		<!--为true时,把JDBC DECIMAL和NUMBERIC类型解析为java.math.BigDecimal-->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- 生成POJO类 -->
		<javaModelGenerator targetPackage="com.wuliu.pojo.po"
			targetProject="src/main/java/">
			<!--是否让schema作为包的后缀-->
			<property name="enableSubPackages" value="false" />
			<!--去除前后空格-->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- 生成mapper映射文件 -->
		<sqlMapGenerator targetPackage="com.wuliu.dao"
			targetProject="src/main/java/">
			<!--同上-->
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>
		<!-- 生成mapper接口 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.wuliu.dao" targetProject="src/main/java/">
			<!--同上-->
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>
		<!-- 指定数据库表 -->
		<table schema="" tableName="provinces"></table>
		<!--<table tableName="UserInfo" domainObjectName="UserInfo"-->
			<!--enableCountByExample="false" enableUpdateByExample="false"-->
			<!--enableDeleteByExample="false" enableSelectByExample="false"-->
			<!--selectByExampleQueryId="false" />-->

	</context>
</generatorConfiguration>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值