mybatis逆向生成工具(自用)

mybatis逆向生成工具,可以通過數據庫映射生成對應pojo類,mapper接口,mapper.xml文件,同時提供通用mapper方法只需要繼承MyMapper類即可直接調用對應的單表增刪改查方法

生成代碼如下:

記錄下自用

一.碼雲下載mybatis-generator工程

我的碼雲地址

二.修改generatorConfig.xml

<generatorConfiguration>
    <context id="MysqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <!-- 通用mapper所在目錄 -->
        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers" value="com.xuxu.my.mapper.MyMapper"/>
        </plugin>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/foodie-shop"
                        userId="root"
                        password="root">
        </jdbcConnection>

        <!-- 對應生成的pojo所在包 -->
        <javaModelGenerator targetPackage="com.xuxu.pojo" targetProject="src/main/java"/>

		<!-- 對應生成的mapper所在目錄 -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>

		<!-- 配置mapper對應的java映射 -->
        <javaClientGenerator targetPackage="com.xuxu.mapper" targetProject="src/main/java" type="XMLMAPPER"/>

        <!-- 數據庫表 -->
		<table tableName="carousel"></table>
		<table tableName="category"></table>
		<table tableName="items"></table>
		<table tableName="items_comments"></table>
		<table tableName="items_img"></table>
		<table tableName="items_param"></table>
		<table tableName="items_spec"></table>
		<table tableName="order_items"></table>
		<table tableName="order_status"></table>
		<table tableName="orders"></table>
		<table tableName="user_address"></table>
		<table tableName="users"></table>

    </context>
</generatorConfiguration>

三.運行GeneratorDisplay中main函數 會生成對應的代碼,將代碼拷入自己的工程對應位置

同時將逆向生成工具工程中的MyMapper拷入之前xml配置的路徑下

四.配置

        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.1.5</version>
        </dependency>

同時啓動類上加入mapper掃描註解,注意這裏mapperScan是tk包下的,配置包路徑指向項目中mapper地址

application.yml配置文件中添加MyMapper的路徑和指定對應數據庫方言

五.調用

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章