1、首先需要下载一下MyBatis Generator
2、解压mybatis-generator-**.zip
3、将mybatis-generator-core-**.jar,数据库驱动,存放的在一起
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>
<!--数据库驱动-->
<classPathEntry location="postgresql-9.4.1212.jre7.jar" />
<context id="context1">
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://172.20.68.242:5432/happinet" userId="postgres"
password="happinet" />
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="cn.pzh.model" targetProject="src/main/java/" />
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="cn.pzh.mapper" targetProject="src/main/resources/" />
<!--生成Mapper接口存放位置-->
<javaClientGenerator targetPackage="cn.pzh.mapper" targetProject="src/main/java/" type="XMLMAPPER" />
<!--生成对应表及类名,tableName="%"代表所有表-->
<table schema="public" tableName="%" enableInsert="true"
enableSelectByPrimaryKey="true"
enableSelectByExample="false"
enableUpdateByPrimaryKey="true"
enableUpdateByExample="false"
enableDeleteByPrimaryKey="true"
enableDeleteByExample="false"
enableCountByExample="false"
selectByExampleQueryId="false"
modelType="hierarchical">
</table>
</context>
</generatorConfiguration>
5、执行命令生成
java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite