一、把mysql-connector-java-5.1.31.jar包放到C盤的mysqljar文件夾下java
二、在generatorConfig.xml文件中配置實體、dao、service等包mysql
<?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>
三、generatorConfig.xml右鍵Generate Mybities/iBATIES Artifacts 便可 就能夠在對應的包下生成文件sql