最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot配置MyBatis-Plus實(shí)現(xiàn)增刪查改

 更新時(shí)間:2021年08月17日 09:30:07   作者:旭東怪  
本文主要介紹了SpringBoot配置MyBatis-Plus實(shí)現(xiàn)增刪查改,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

1 MyBatis-Plus 

        MyBatis-Plus (opens new window)(簡(jiǎn)稱 MP)是一個(gè)MyBatis (opens new window)的增強(qiáng)工具,在 MyBatis 的基礎(chǔ)上只做增強(qiáng)不做改變,為簡(jiǎn)化開(kāi)發(fā)、提高效率而生。

        特性:

        (1)無(wú)侵入:只做增強(qiáng)不做改變,引入它不會(huì)對(duì)現(xiàn)有工程產(chǎn)生影響,如絲般順滑。

        (2)損耗?。?jiǎn)?dòng)即會(huì)自動(dòng)注入基本 CURD,性能基本無(wú)損耗,直接面向?qū)ο蟛僮鳌?/p>

        (3)強(qiáng)大的 CRUD 操作:內(nèi)置通用 Mapper、通用 Service,僅僅通過(guò)少量配置即可實(shí)現(xiàn)單表大部分 CRUD 操作,更有強(qiáng)大的條件構(gòu)造器,滿足各類使用需求。

        (4)支持 Lambda 形式調(diào)用:通過(guò) Lambda 表達(dá)式,方便的編寫(xiě)各類查詢條件,無(wú)需再擔(dān)心字段寫(xiě)錯(cuò)。

        (5)支持主鍵自動(dòng)生成:支持多達(dá) 4 種主鍵策略(內(nèi)含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解決主鍵問(wèn)題。

        (6)支持 ActiveRecord 模式:支持 ActiveRecord 形式調(diào)用,實(shí)體類只需繼承 Model 類即可進(jìn)行強(qiáng)大的 CRUD 操作。

        (7)支持自定義全局通用操作:支持全局通用方法注入( Write once, use anywhere )。

        (8)內(nèi)置代碼生成器:采用代碼或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 層代碼,支持模板引擎,更有超多自定義配置等您來(lái)使用。

        (9)內(nèi)置分頁(yè)插件:基于 MyBatis 物理分頁(yè),開(kāi)發(fā)者無(wú)需關(guān)心具體操作,配置好插件之后,寫(xiě)分頁(yè)等同于普通 List 查詢。

        (10)分頁(yè)插件支持多種數(shù)據(jù)庫(kù):支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多種數(shù)據(jù)庫(kù)。

        (11)內(nèi)置性能分析插件:可輸出 SQL 語(yǔ)句以及其執(zhí)行時(shí)間,建議開(kāi)發(fā)測(cè)試時(shí)啟用該功能,能快速揪出慢查詢。

        (12)內(nèi)置全局?jǐn)r截插件:提供全表 delete 、 update 操作智能分析阻斷,也可自定義攔截規(guī)則,預(yù)防誤操作。

2 Maven依賴

		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>2.2.0</version>
		</dependency>
		<!--MySQL數(shù)據(jù)庫(kù)連接驅(qū)動(dòng)-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.4.1</version>
		</dependency>

3 Spring Boot配置

#數(shù)據(jù)庫(kù)連接池設(shè)置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456
 
#mybatis的相關(guān)配置
mybatis.mapper-locations=classpath:mapper/*.xml

4 UserEntity

用戶信息實(shí)體類。

package com.entity;
 
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
 
/**
 * 用戶信息實(shí)體類
 */
@Data
@TableName("users")
public class UserEntity {
    /**
     * 用戶名
     */
    @TableField("username")
    @TableId
    private String username;
    /**
     * 昵稱
     */
    @TableField("pickname")
    private String pickname;
    /**
     * 密碼
     */
    @TableField("password")
    private String password;
    /**
     * 性別
     */
    @TableField("sex")
    private String sex;
}

5 UserMapper

用戶信息dao層。

package com.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
 
/**
 * 用戶信息dao層
 */
@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {
}

6 Service(業(yè)務(wù)邏輯層)

6.1 UserService

package com.service;
 
import com.baomidou.mybatisplus.extension.service.IService;
import com.entity.UserEntity;
 
public interface UserService extends IService<UserEntity> {
}

6.2 UserServiceImpl

package com.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.entity.UserEntity;
import com.mapper.UserMapper;
import com.service.UserService;
import org.springframework.stereotype.Service;
 
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,UserEntity> implements UserService  {
}

7 UserController

調(diào)試代碼。

package com.controller;
 
import com.entity.UserEntity;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@RestController
public class UserController {
    @Autowired
    private UserService userService;
 
    /**
     * 獲取所有用戶數(shù)據(jù)
     *
     * @return
     */
    @GetMapping("/getList")
    public List<UserEntity> getList() {
        return userService.list();
    }
 
    /**
     * 插入用戶數(shù)據(jù)
     *
     * @return
     */
    @PostMapping("/create")
    public boolean create(@RequestBody UserEntity userEntity) {
        return userService.save(userEntity);
    }
 
    /**
     * 更新用戶數(shù)據(jù)
     *
     * @return
     */
    @PutMapping("/update")
    public boolean update(@RequestBody UserEntity userEntity) {
        return userService.updateById(userEntity);
    }
 
    /**
     * 刪除用戶數(shù)據(jù)
     *
     * @return
     */
    @DeleteMapping("/delete/{username}")
    public boolean delete(@PathVariable("username") String username) {
        return userService.removeById(username);
    }
}

8 調(diào)試結(jié)果  

8.1 查詢數(shù)據(jù)

8.2 新增數(shù)據(jù)

 

8.3 更新數(shù)據(jù) 

8.4 刪除數(shù)據(jù)

 

到此這篇關(guān)于SpringBoot配置MyBatis-Plus實(shí)現(xiàn)增刪查改的文章就介紹到這了,更多相關(guān)SpringBoot MyBatis-Plus增刪查改內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

胶州市| 峡江县| 南昌县| 罗平县| 云南省| 万源市| 津市市| 大田县| 阳江市| 乡城县| 大悟县| 梅州市| 邵阳县| 万年县| 文水县| 黄龙县| 布拖县| 绍兴县| 达尔| 保德县| 青海省| 丘北县| 将乐县| 新晃| 岗巴县| 樟树市| 左贡县| 扎赉特旗| 昌都县| 辉南县| 阳朔县| 上犹县| 平安县| 邵武市| 韩城市| 合山市| 文水县| 湘阴县| 苗栗县| 开阳县| 佛学|