mybatis逆向工程的使用
阿新 • • 發佈:2021-06-22
1,.安裝逆向工程外掛
<!--mybatis 逆向工程程式碼自動生成外掛--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <!--配置檔案的位置--> <configurationFile>GeneratorMapper.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin>
2.逆向工程配置檔案,放到資源根目錄(資料庫連線四要素:驅動,地址,使用者名稱密碼)
<?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> <!-- 需要指定一個本地的mysql驅動 --> <classPathEntry location="D:\apache_work\mysql-connector-java-5.1.23.jar"/> <context id="tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 配置資料庫連線資訊 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/springboot" userId="root" password="333"> </jdbcConnection> <!-- 指定生成實體類的存放位置--> <javaModelGenerator targetPackage="com.bjpowernode.springboot.pojo" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="false" /> </javaModelGenerator> <!--指定生成的mapper的位置 --> <sqlMapGenerator targetPackage="com.bjpowernode.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!--指定生成的dao介面位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.bjpowernode.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 指定生成哪些表對應的實體類,與生成的實體類名--> <table tableName="tbl_student" domainObjectName="Student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> </context> </generatorConfiguration>
點選外掛,並執行,完成