对于一个字段太多的表,如果一个一个的去写 mapper和pojo太累还容易出错,可用mybatis的工具处理这些事情
参考:http://blog.csdn.net/jinshiyill/article/details/51546676 官方网址: http://www.mybatis.org/generator/configreference/xmlconfig.html 原码:http://download.csdn.net/detail/wangxy799/9773975
1. 环境:
Maven 3.39 Oracle 11g Mybatis 3.4.1 Maven project
2. 目录结构
3. pom添加插件
<dependencies>
<dependency>
<groupId>org.mybatis
</groupId>
<artifactId>mybatis
</artifactId>
<version>3.4.1
</version>
</dependency>
<dependency>
<groupId>junit
</groupId>
<artifactId>junit
</artifactId>
<version>4.12
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator
</groupId>
<artifactId>mybatis-generator-maven-plugin
</artifactId>
<version>1.3.5
</version>
</plugin>
</plugins>
</build>
4. 新建generatorConfig.xml 文件(放在src/main/resources目录下)
<?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>
<properties resource="application.properties"/>
<classPathEntry
location="${generator.location}" />
<context id="sqlserverTables">
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="${db.example.driver}"
connectionURL="${db.example.url}" userId="${db.example.username}"
password="${db.example.password}">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="${generator.targetPackage}"
targetProject="./src/main/java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="${generator.targetPackage}"
targetProject="./src/main/java">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="${generator.targetPackage}" targetProject="./src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="${gererator.tableName}" domainObjectName="${gererator.objectName}"
schema="${gererator.schema}"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
5. 设置需要生成的表及创建目录参数(application.properties放在src/main/resources目录下)
db
.example.type=oracle
db
.example.driver=oracle
.jdbc.driver.OracleDriver
db
.example.url=jdbc:oracle:thin:@ip:port:sid
db
.example.username=username
db
.example.password=password
#MBGInfo
generator
.location=D:/project/eas_std/BaseApp/lib/ojdbc14-
10.2.0.5.jar
generator
.targetPackage=
com.zteict.example.menu
gererator
.schema=fbp
gererator
.tableName=fbp_menu
gererator
.objectName=FbpMenu
6. 项目右键-RUN AS-MAVEN BUILD..
输入 mybatis-generator:generate
7. 生成的文件
FbpMenu: FbpMenuMapper: Xml:
转载请注明原文地址: https://ju.6miu.com/read-1596.html