MybatisX快速生成增刪改查的方法示例
MybatisX 是一款基于 IDEA 的快速開發(fā)插件,方便在使用mybatis以及mybatis-plus開始時簡化繁瑣的重復(fù)操作,提高開發(fā)速率。注意:idea得用最新的版本才能生效一些功能,我用的是2021.3版本的
1 安裝
file - settings - plugins - mybatisx

2 基本功能
搭建測試項目
- 導(dǎo)入依賴
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.1 xml跳轉(zhuǎn)
添加插件后在dao層會多一只戴紅色頭巾的小鳥,同樣在對應(yīng)xml文件方法前也會對應(yīng)一直戴藍(lán)色頭巾的小鳥,點擊即可在dao和xml文件之間跳轉(zhuǎn)

點擊上面的紅色小鳥可以跳轉(zhuǎn)到
SingerMapper.xml文件

點擊上面的藍(lán)色小鳥可以跳轉(zhuǎn)到
SingerDao.java
2.2 代碼生成
2.2.1 生成.xml中的sql語句頭
以前我們在開發(fā)中寫好接口后,還要到xml中寫對應(yīng)的xml方法,有了MybatisX后只用在dao中寫好對應(yīng)方法后,按Alt+Enter選擇自動生成就能自動在xml中生成對應(yīng)的映射方法

生成結(jié)果:

拓展:entity類建立映射:
<resultMap id="BaseResultMap" type="com.example.mybatisxtest.entity.Singer">
<result column="id" jdbcType="INTEGER" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="sex" jdbcType="TINYINT" property="sex"/>
<result column="pic" jdbcType="VARCHAR" property="pic"/>
<result column="birth" jdbcType="TIMESTAMP" property="birth"/>
<result column="location" jdbcType="VARCHAR" property="location"/>
<result column="introduction" jdbcType="VARCHAR" property="introduction"/>
</resultMap>

2.2.2 根據(jù)數(shù)據(jù)庫表,自動生成增刪改查
- 添加數(shù)據(jù)庫
view - tool windows - database

導(dǎo)入數(shù)據(jù)庫:

填寫數(shù)據(jù)源配置:

選中表,右鍵生成

選擇配置(具體需要大家可以自行選擇,沒有就默認(rèn)即可)

生成結(jié)果:

選擇不同template,會得到不同效果
default all:

mybatis-plus2模板:

生成結(jié)果:

2.3 JPA提示和生成語句
MybatisX會根據(jù)實體字段寫出方法名

根據(jù)方法名生成對應(yīng)SQL

生成結(jié)果:
SingerMapper.java:
List selectByIntroduction(@Param(“introduction”) String introduction);
SingerMapper.xml:
<select id="selectByIntroduction" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from singer
where
introduction = #{introduction,jdbcType=VARCHAR}
</select>
到此這篇關(guān)于MybatisX快速生成增刪改查的方法示例的文章就介紹到這了,更多相關(guān)MybatisX生成增刪改查內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
springsecurity?登錄認(rèn)證流程分析一(ajax)
這篇文章主要介紹了springsecurity?登錄認(rèn)證一(ajax篇),本文通過實例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-08-08
SpringBoot項目請求不中斷動態(tài)更新代碼的實現(xiàn)
在開發(fā)中,有時候不停機動態(tài)更新代碼熱部署是一項至關(guān)重要的功能,它可以在請求不中斷的情況下下更新代碼,這種方式不僅提高了開發(fā)效率,還能加速測試和調(diào)試過程,本文將詳細(xì)介紹如何在 Spring Boot 項目在Linux系統(tǒng)中實現(xiàn)熱部署,特別關(guān)注優(yōu)雅關(guān)閉功能的實現(xiàn)2024-09-09
Java語言----三種循環(huán)語句的區(qū)別介紹
下面小編就為大家?guī)硪黄狫ava語言----三種循環(huán)語句的區(qū)別介紹。小編舉得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07
Spring Boot中使用Spring-Retry重試框架的實現(xiàn)
本文主要介紹了Spring Boot中使用Spring-Retry重試框架的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
SpringBoot中fastjson自定義序列化和反序列化的實戰(zhàn)分享
在fastjson庫中,為了提供靈活的序列化和反序列化機制,設(shè)計了一系列的擴展點,以下是在SpringBoot和SpringClould環(huán)境中對這些擴展點的詳細(xì)介紹及其實戰(zhàn)使用,通過代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-07-07
Java try()語句實現(xiàn)try-with-resources異常管理機制操作
這篇文章主要介紹了Java try()語句實現(xiàn)try-with-resources異常管理機制操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09
springboot單文件下載和多文件壓縮zip下載的實現(xiàn)
這篇文章主要介紹了springboot單文件下載和多文件壓縮zip下載的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11

