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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
3.生成对应实体类和mapper文件