Mybatis-Generator生成model、dao、xml映射文件–基于eclipse插件
1.在Eclipse Marketplace搜索安装Mybatis-Generator插件,重启eclipse
2.导入需要的包:mysql驱动jar包、mybatis-generator-core.jar
3.新建generatorConfig.xml
4.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>
<context id="context1">
<!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 配置数据源 -->
<jdbcConnection
connectionURL="jdbc:mysql://localhost:3306/ssm_crud"
driverClass="com.mysql.jdbc.Driver"
userId="root"
password="123456" />
<!-- 指定Javabean生成的位置 -->
<javaModelGenerator targetPackage="com.credit.bean" targetProject="credit" />
<!-- 指定sql映射文件生成的位置 -->
<sqlMapGenerator targetPackage="mapper" targetProject="credit" />
<!-- 指定DAO接口生成的位置 -->
<javaClientGenerator targetPackage="com.credit.dao" targetProject="credit" type="XMLMAPPER" />
<!-- 指定数据库的表名 ===>对应生成的实体名-->
<table tableName="credit_user" domainObjectName="creditUser"></table>
</context>
</generatorConfiguration>
5.generatorConfig配置文件右键=>Run As=>Run Mybatis Generator
6.项目结构