配置文件:mybatis-generator.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="DB2Tables" targetRuntime="MyBatis3">
<!-- Mysql数据库链接地址账号密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/databaseName"
userId="root" password="root">
</jdbcConnection>
<!-- 生成DataObject类存放位置 -->
<javaModelGenerator targetPackage="com.project.dataobject"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成Dao接口存放位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.project.dao"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 根据数据库表生成对应Object及Mapper -->
<table tableName="user_info" domainObjectName="UserDO"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="user_password" domainObjectName="UserPasswordDO"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
最后唠叨一句,如果数据库表搞定后,用IDEA的童鞋可以参考下面操作步骤
1、打开 Run/Debug Configurations
2、新建一个Maven命令
3、在Command line 中填入 mybatis-generator:generate
4、Apply Ok,最后点击运行刚刚新建的命令