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

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

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

1 MyBatis-Plus 

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

        特性:

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

        (2)損耗小:啟動(dòng)即會自動(dòng)注入基本 CURD,性能基本無損耗,直接面向?qū)ο蟛僮鳌?/p>

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

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

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

        (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 層代碼,支持模板引擎,更有超多自定義配置等您來使用。

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

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

        (11)內(nèi)置性能分析插件:可輸出 SQL 語句以及其執(zhí)行時(shí)間,建議開發(fā)測試時(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ù)庫連接驅(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ù)庫連接池設(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

武夷山市| 临高县| 东光县| 永安市| 望江县| 建阳市| 上杭县| 冀州市| 湘西| 房山区| 兴化市| 光泽县| 乌拉特后旗| 长宁区| 迁西县| 民乐县| 仁布县| 于都县| 龙游县| 且末县| 莒南县| 灌云县| 镇雄县| 高淳县| 比如县| 乾安县| 兴海县| 海伦市| 精河县| 云霄县| 江油市| 抚宁县| 铅山县| 通江县| 灵寿县| 鹤山市| 柯坪县| 磴口县| 西畴县| 福鼎市| 慈利县|