Eclipse+MyBatis自動生成Mapper和實體還有對應sqlxml
阿新 • • 發佈:2018-12-22
1.安裝外掛(eclipse的marketplace中搜索mybatis就行了)
2.建立generatorConfig.xml檔案(配置資料庫等資訊,讀懂這個檔案的內容就行了)
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>
<classPathEntry location="E:/jar/mysql-connector-java-5.1.25.jar" />
<context id="context1">
<!-- 生成的pojo,將implements Serializable -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<commentGenerator >
<!-- 是否去除自動生成的註釋 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/hongbaodb?characterEncoding=utf8"
userId="kevinLee" password="1234" />
<javaModelGenerator targetPackage="com.ithaha.pojo"
targetProject="redpacket" />
<sqlMapGenerator targetPackage="com.ithaha.mapper"
targetProject="redpacket" />
<javaClientGenerator targetPackage="com.ithaha.mapper"
targetProject="redpacket" type="XMLMAPPER" />
<table schema="RedPacket" tableName="t_red_packet"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" domainObjectName="RedPacket"></table>
<table schema="UserRedPacket" tableName="t_user_red_packet"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" domainObjectName="UserRedPacket"></table>
</context>
</generatorConfiguration>