1.先新建一个Maven(war)项目
2.添加mysql的jar包可以直接在网上下载
3.在src/main/resources
4.在generatorConfig.properties这个文件中写入如下的代码:
suppressAllComments=false
driverClass=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/phonemarket_db?characterEncoding=utf-8
username=root
password=root
modeltargetPackage=com.tx.sys.pojo
targetProject=TXMarket
sqltargetPackage=com.tx.sys.mapper
clienttargetPackage=com.tx.sys.dao
解释如下:
5.在中代码如下
<?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>
<!-- 配置属性文件,这样有变更只需改配置文件 -->
<properties resource="generatorConfig.properties"/>
<!-- 指定mysql的驱动包的路径 千万别放中文路径下 -->
<classPathEntry location="D:\mysql-connector-java-5.1.32\mysql-connector-java-5.1.32.jar" />
<!-- 配置数据源和生成的代码所存放的位置 -->
<context id="tarena">
<!-- 是否生成注释 true不生成 false生成 -->
<commentGenerator>
<property name="suppressAllComments" value="${suppressAllComments}"/>
</commentGenerator>
<jdbcConnection driverClass="${driverClass}" connectionURL="${url}" userId="${username}" password="${password}" />
<!-- 所生成的实体类的位置默认资源包src -->
<javaModelGenerator targetPackage="${modeltargetPackage}" targetProject="${targetProject}" />
<!-- 所生成的sqlMap的影射文件的位置,默认资源包src -->
<sqlMapGenerator targetPackage="${sqltargetPackage}" targetProject="${targetProject}" />
<javaClientGenerator targetPackage="${clienttargetPackage}" targetProject="${targetProject}" type="XMLMAPPER" />
<!-- 为哪些表生成代码 tableName:表名 schema:不用填写 -->
<table schema="" tableName="address" />
<table schema="" tableName="admins" />
<table schema="" tableName="areas" />
<table schema="" tableName="banner" />
<table schema="" tableName="cart" />
<table schema="" tableName="cities" />
<table schema="" tableName="evaimg" />
<table schema="" tableName="evaluate" />
<table schema="" tableName="funs" />
<table schema="" tableName="goods" />
<table schema="" tableName="goods_type" />
<table schema="" tableName="guess" />
<table schema="" tableName="memory" />
<table schema="" tableName="order" />
<table schema="" tableName="order_detail" />
<table schema="" tableName="permissions" />
<table schema="" tableName="provinces" />
<table schema="" tableName="role" />
<table schema="" tableName="users" />
<table schema="" tableName="zipcode" />
</context>
</generatorConfiguration>
解释如下:
6.在eclipse中配置两个文件夹如下
本来想把这两个文件夹传上来的,但是我试过了不能传,有需要的可以跟我说可以微信或者qq发给你