欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

將Mybatis升級為Mybatis-Plus的詳細過程

 更新時間:2025年04月04日 09:03:52   作者:HelloDam  
本文詳細介紹了在若依管理系統(tǒng)(v3.8.8)中將MyBatis升級為MyBatis-Plus的過程,旨在提升開發(fā)效率,通過本文,開發(fā)者可實現系統(tǒng)功能無損升級,同時享受MyBatis-Plus帶來的便捷特性,如代碼簡化和性能優(yōu)化,需要的朋友可以參考下

說明

若依管理系統(tǒng)是一個非常完善的管理系統(tǒng)模板,里面含有代碼生成的方法,可以幫助用戶快速進行開發(fā),但是項目使用的是mybatis,對于熟悉使用mybatis-plus進行開發(fā)的小伙伴們不是很便捷,本文主要講解如何在不影響系統(tǒng)現有功能的基礎上,將mybatis升級為mybatis-plus,以幫助小伙伴們更快速地開發(fā)。

我所使用的若依版本為:v3.8.8

流程

增加依賴

【首先修改父模塊的pom.xml文件】

分別在properties標簽內和dependencies標簽內增加內容,所需增加的內容如下面的xml

    <properties>
        <mybatis-plus.version>3.2.0</mybatis-plus.version>
    </properties>

    <!-- 依賴聲明 -->
    <dependencyManagement>
        <dependencies>

            <!-- mybatis-plus -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

【其次修改common包下的pom.xml文件】

直接在dependencies標簽內增加如下內容即可,因為父模塊已經管理了版本,這里不需要再聲明版本

 <dependency>
     <groupId>com.baomidou</groupId>
     <artifactId>mybatis-plus-boot-starter</artifactId>
 </dependency>

修改配置文件

需要修改admin包下的application.yml文件

注釋掉mybatis的配置之后(mybatis-plus是兼容mybatis的,小伙伴們放心注釋就行),增加mybatis-plus的配置,配置如下

mybatis-plus:
  mapper-locations: classpath*:mapper/**/*Mapper.xml
  type-aliases-package: com.ruoyi.**.domain
  global-config:
    db-config:
      id-type: auto
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

注釋掉MybatisConfig里面的Bean

系統(tǒng)會自動根據配置文件構建mybatisplus相關的Bean,所以這里也不需要修改成mybatis-plus的

修改之后記得重新 install framework包,這樣修改才會生效

代碼生成

上面的操作雖然是將mybatis-plus引入了,但是有小伙伴疑問了,使用若依管理系統(tǒng)自帶的代碼生成器,生成的還是mybatis的代碼呀,那怎么辦呢?

為了解決小伙伴們心中的疑惑,我這里提供一種解決思路,那就是結合IDEA生成的代碼和若依代碼生成器的代碼。

使用IDEA生成代碼

首先安裝下面的插件,記得安裝1.5.5版本的插件,高版本的插件可能會有問題(我之前是安裝的高版本,出問題之后才回退的),具體安裝可以去閱讀其他博主的教程

生成成功,由下圖可知,除了controller外,其他代碼都已經生成成功

注意

使用MybatisX生成的實體類是沒有邏輯刪除等注解的,如果需要使用邏輯刪除,或者自動填充ID和時間,需要在實體類上面添加注解

Controller文件

Controller文件直接使用若依的代碼生成器生成即可,使用這種方式生成的好處是,若依會生成對應的前端文件,這樣可以直接搭配使用,不需要再去修改生成的api

雖然若依生成器生成了Controller代碼,但是沒辦法直接將其進行應用,因為我們前面生成的Service文件使用的是mybatis-plus,所以還需要對Controller文件進行修改,修改的方式可以參考我下面的代碼,當然這個代碼還是非常不完善的,比如數據校驗那些都沒有

package com.shm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.Follow;
import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.shm.service.IFollowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 關注Controller
 *
 * @author dam
 * @date 2023-08-08
 */
@RestController
@RequestMapping("/market/follow")
public class FollowController extends BaseController {
    @Autowired
    private IFollowService followService;

    /**
     * 查詢關注列表
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:list')")
    @GetMapping("/list")
    public TableDataInfo list(Follow follow) {
        startPage();
        List<Follow> list = followService.list(new QueryWrapper<Follow>(follow));
        return getDataTable(list);
    }

    /**
     * 導出關注列表
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:export')")
    @Log(title = "關注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Follow follow) {
        List<Follow> list = followService.list(new QueryWrapper<Follow>(follow));
        ExcelUtil<Follow> util = new ExcelUtil<Follow>(Follow.class);
        util.exportExcel(response, list, "關注數據");
    }

    /**
     * 獲取關注詳細信息
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(followService.getById(id));
    }

    /**
     * 新增關注
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:add')")
    @Log(title = "關注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Follow follow) {
        // 設置商品主人
        LoginUser loginUser = getLoginUser();
        follow.setFollowerId(loginUser.getUserId());
        return toAjax(followService.save(follow));
    }

    /**
     * 修改關注
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:edit')")
    @Log(title = "關注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Follow follow) {
        return toAjax(followService.updateById(follow));
    }

    /**
     * 刪除關注
     */
    @PreAuthorize("@ss.hasPermi('shm:follow:remove')")
    @Log(title = "關注", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(followService.removeByIds(ids));
    }
}

以上就是將Mybatis升級為Mybatis-Plus的詳細過程的詳細內容,更多關于Mybatis升級為Mybatis-Plus的資料請關注腳本之家其它相關文章!

相關文章

  • 淺談SpringBoot是如何實現日志的

    淺談SpringBoot是如何實現日志的

    這篇文章主要介紹了淺談SpringBoot是如何實現日志的,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • IDEA在一個工作空間中管理多個項目的詳細步驟

    IDEA在一個工作空間中管理多個項目的詳細步驟

    這篇文章主要介紹了IDEA在一個工作空間中管理多個項目的詳細步驟,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • springboot多環(huán)境配置文件及自定義配置文件路徑詳解

    springboot多環(huán)境配置文件及自定義配置文件路徑詳解

    這篇文章主要介紹了springboot多環(huán)境配置文件及自定義配置文件路徑,文中給大家介紹了classpath的基本概念講解及自定義springboot配置文件路徑的相關知識,需要的朋友可以參考下
    2023-02-02
  • Java Swing組件實現進度監(jiān)視功能示例

    Java Swing組件實現進度監(jiān)視功能示例

    這篇文章主要介紹了Java Swing組件實現進度監(jiān)視功能,結合完整實例形式詳細分析了Java基于Swing組件實現進度條顯示功能的具體操作技巧與相關注意事項,需要的朋友可以參考下
    2018-02-02
  • spring boot項目導入依賴后代碼報錯問題的解決方法

    spring boot項目導入依賴后代碼報錯問題的解決方法

    這篇文章主要給大家介紹了關于spring boot項目導入依賴后代碼報錯問題的解決方法,文中通過示例代碼介紹的非常詳細,對大家學習或者使用spring Boot具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2020-08-08
  • Spring Bean創(chuàng)建和循環(huán)依賴

    Spring Bean創(chuàng)建和循環(huán)依賴

    這篇文章主要介紹了Spring Bean創(chuàng)建和循環(huán)依賴,講述了Spring容器中?Bean?的創(chuàng)建過程已經主要的方法,另外也著重分析了循環(huán)依賴的問題,需要的小伙伴可以參考一下
    2022-05-05
  • 在eclipse中使用SVN的方法(圖文)

    在eclipse中使用SVN的方法(圖文)

    這篇文章主要介紹了在eclipse中使用SVN的方法(圖文),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • SpringSecurity構建基于JWT的登錄認證實現

    SpringSecurity構建基于JWT的登錄認證實現

    這篇文章主要介紹了SpringSecurity構建基于JWT的登錄認證實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-02-02
  • Spring?Security權限管理小結

    Spring?Security權限管理小結

    SpringSecurity是一個權限管理框架,核心是認證和授權,前面已經系統(tǒng)的給大家介紹過了認證的實現和源碼分析,本文重點來介紹下權限管理,需要的朋友可以參考下
    2022-08-08
  • Spring中@Autowired自動注入map詳解

    Spring中@Autowired自動注入map詳解

    這篇文章主要介紹了Spring中@Autowired自動注入map詳解,  spring是支持基于接口實現類的直接注入的,支持注入map,list等集合中,不用做其他的配置,直接注入,需要的朋友可以參考下
    2023-10-10

最新評論