这篇文章主要讲解用maven的方式自动生成映射文件
1.在项目pom.xml中配置mybatis,利用maven下载mybatis
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</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>
<?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="E:/Users/chenjing/Documents/mysql/mysql-connector-java-5.0.8-bin.jar" />
<context id="DBTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
</commentGenerator>
<!-- 数据库的url、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/" userId="userId" password="password">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.chenjing.domain" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="com.chenjing.mapping" targetProject="src/main/source">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.chenjing.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 生成那些表 tableName表名,domainObjectName应于数据库表的javaBean类名-->
<table tableName="st_user" domainObjectName="ST_UserInfoDO"tByExample="false">
<property name="useActualColumnNames" value="true"/>
<generatedKey column="ID" sqlStatement="SELECT LAST_INSERT_ID()" identity="true"/>
</table>
</context>
</generatorConfiguration>3.在maven project 窗口找到mybatis插件,执行插件即可生成对应的映射文件。
本文详细介绍了如何在Maven项目中配置MyBatis,以实现映射文件的自动生成,帮助开发者简化开发流程。
675

被折叠的 条评论
为什么被折叠?



