一、利用maven配置jar就引入依赖
详情地址
二、手动引入jar包
三、generatorConfig.xml
1. 运行配置文件就能自动生成pojo和mapper
2. 生成generatorConfig.xml
项目右键→new→other→myba… 下边的文件,next。。。
配置文件
<?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:\Mybatis\mysql-connector-java-5.1.38.jar" />
<!-- targetRuntime
MyBatis3 :默认的值,生成基于MyBatis3.X以上版本的内容 包括XXXBySample;
MyBatis3Simpl :类似于MyBatis3 但是不生成XXXBySample -->
<context id="mysql" targetRuntime="MyBatis3Simple">
<commentGenerator>
<property name="suppressDate" value="true" />
<!-- 是否去除自动生成的注释 true是/false否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/pingpang" userId="root" password="1234">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 设置实体类所在的项目与包的位置 -->
<javaModelGenerator targetPackage="com.bian.pojo" targetProject="MybatiesTest\src">
<!-- <property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" /> -->
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="com.bian.mapper" targetProject="MybatiesTest\src">
<!-- <property name="enableSubPackages" value="true" /> -->
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator targetPackage="com.bian.mapper" targetProject="MybatiesTest\src" type="XMLMAPPER">
<!-- <property name="enableSubPackages" value="true" /> -->
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名 -->
<table schema="bian" tableName="adress" domainObjectName="Adress">
是否使用表中的列表生成类中的成员变量名
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 场地表 -->
<table schema="pingpang" tableName="field" domainObjectName="Field">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 财务表 -->
<table schema="pingpang" tableName="finance" domainObjectName="Finance">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 权限表 -->
<table schema="pingpang" tableName="rule" domainObjectName="Rule">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 角色表 -->
<table schema="pingpang" tableName="role" domainObjectName="Role">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 角色——权限联合查询表 -->
<table schema="pingpang" tableName="rule_role" domainObjectName="Rule_Role">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 开台表 -->
<table schema="pingpang" tableName="table" domainObjectName="Table">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
<!-- 员工表 -->
<table schema="pingpang" tableName="user" domainObjectName="User">
<!-- 是否使用表中的列表生成类中的成员变量名 -->
<property name="useActualColumnNames" value="false"/>
</table>
</context>
</generatorConfiguration>