1、把mysql-connector-java-5.1.31.jar包放到C盘的mysqljar文件夹下
2、在generatorConfig.xml文件中配置实体、dao、service等包
<?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="C:/mysqljar/mysql-connector-java-5.1.31.jar"/> <context id="context1"> <!-- 生成文件编码 --> <property name="javaFileEncoding" value="UTF-8"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 数据库 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/future?useUnicode=true&characterEncoding=UTF-8" userId="root" password="root" /> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.future.base.dao.entity" targetProject="future-base"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="com.future.base.dao.mapper" targetProject="future-base"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.future.base.dao" targetProject="future-base"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 表名 实体 --> <table tableName="reader_type" domainObjectName="ReaderType" > <!-- 有主键 id 就加 。。没有 就 不要这个 --> <generatedKey column="id" sqlStatement="MySql" identity="true"/> </table> </context> </generatorConfiguration>
3、generatorConfig.xml右键Generate Mybities/iBATIES Artifacts 即可 就可以在对应的包下生成文件