@[toc]java
簡單點說,就是經過數據庫中的單表,自動生成java代碼。Mybatis官方提供了逆向工程,能夠針對單表自動生成mybatis代碼(mapper.java\mapper.xml\po類)企業中,逆向工程是個很經常使用的工具,比咱們手動建立映射文件的配置信息方便不少.mysql
eclipse中安裝Generate插件 sql
隨便什麼項目數據庫
在src下建立一個配置文件 mybatis
<?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:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.27\mysql-connector-java-5.1.27.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 去掉生成文件中的註釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 數據庫連接URL、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/demo" userId="root" password="1234"> </jdbcConnection> <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:XE" userId="car" password="car"> </jdbcConnection> --> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.sxt.pojo" targetProject="Mybatis19-generator\src\main\java"> <!-- 是否在當前路徑下新加一層schema,eg:fase路徑com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="com.sxt.mapper" targetProject="Mybatis19-generator\src\main\java"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.sxt.mapper" targetProject="Mybatis19-generator\src\main\java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table tableName="t_user" domainObjectName="User" > </table> </context> </generatorConfiguration>