發布時間: 2018-09-13 23:46:32
1:在pom.xml文件中添加必須的依賴
<!--逆向工程--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin> 2:在resources目錄下編寫generatorConfig.xml文件: <?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> <!--數據庫驅動jar --> <classPathEntry location="D:\JavaUtilsIdea\M2\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" /> <context id="Tables" targetRuntime="MyBatis3"> <!--去除注釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--數據庫連接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mybatis" userId="root" password="123456"> </jdbcConnection> <!--默認false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!--生成實體類 指定包名 以及生成的地址 (可以自定義地址,但是路徑不存在不會自動創建 使用Maven生成在target目錄下,會自動創建) --> <javaModelGenerator targetPackage="net.togogo.bean" targetProject="D:\JianGuoYun\MyStu\MyBatisStu\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--生成SQLMAP文件 --> <sqlMapGenerator targetPackage="net.togogo.mapper" targetProject="D:\JianGuoYun\MyStu\MyBatisStu\src\main\java"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao實現 context id="DB2Tables" 修改targetRuntime="MyBatis3" --> <javaClientGenerator type="XMLMAPPER" targetPackage="mapper" targetProject="D:\JianGuoYun\MyStu\MyBatisStu\src\main\java\net\togogo"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!--對應數據庫表 mysql可以加入主鍵自增 字段命名 忽略某字段等 --> <table tableName="t_user" domainObjectName="User" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" /> </context> </generatorConfiguration>
上一篇: {HTML5}基礎核心-第二節-中
下一篇: {HTML5}基礎核心-第二節-中