1. 程式人生 > >Eclipse+MyBatis自動生成Mapper和實體還有對應sqlxml

Eclipse+MyBatis自動生成Mapper和實體還有對應sqlxml

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>

3.生成對應實體類和mapper檔案

這裡寫圖片描述