国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:2日期:2023-12-01 15:27:34
目錄1 MyBatis-Plus 2 Maven依賴3 Spring Boot配置4 UserEntity5 UserMapper6 Service(業(yè)務(wù)邏輯層)6.1 UserService6.2 UserServiceImpl7 UserController8 調(diào)試結(jié)果 8.1 查詢數(shù)據(jù)8.2 新增數(shù)據(jù)8.3 更新數(shù)據(jù) 8.4 刪除數(shù)據(jù)1 MyBatis-Plus

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

特性:

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

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

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

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

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

(6)支持 ActiveRecord 模式:支持 ActiveRecord 形式調(diào)用,實體類只需繼承 Model 類即可進行強大的 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í)行時間,建議開發(fā)測試時啟用該功能,能快速揪出慢查詢。

(12)內(nèi)置全局攔截插件:提供全表 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ū)動--><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.Driverspring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8spring.datasource.username=rootspring.datasource.password=123456 #mybatis的相關(guān)配置mybatis.mapper-locations=classpath:mapper/*.xml4 UserEntity

用戶信息實體類。

package com.entity; import com.baomidou.mybatisplus.annotation.*;import lombok.Data; /** * 用戶信息實體類 */@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層 */@Mapperpublic 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; @Servicepublic 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; @RestControllerpublic 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ù)

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

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

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

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

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

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

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

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

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 一区二区三区四区视频在线观看 | 五月激情丁香婷婷综合第九 | 亚洲欧美第一 | 欧美一级xxxx俄罗斯一级 | 国产成人www免费人成看片 | 日本中文字幕不卡免费视频 | 国产精品亚洲国产三区 | 亚洲国产一区二区a毛片日本 | 二区久久国产乱子伦免费精品 | 日韩欧美精品综合一区二区三区 | 一区二区三区国产精品 | 99ri在线精品视频在线播放 | 福利片成人午夜在线 | 国产裸体美女视频全黄 | 6一10周岁毛片免费 6一12呦女精品 | 欧美日韩一区二区三区四区在线观看 | 久久男人的天堂色偷偷 | 老鸭窝 国产 精品 91 | 99国产福利视频区 | 九九视频高清视频免费观看 | 97国内免费久久久久久久久久 | 国产成人综合亚洲亚洲欧美 | 欧美人在线一区二区三区 | 久久影院在线 | 毛片网站免费在线观看 | 国产成人在线视频网站 | 色毛片 | 九九视频在线观看6 | 欧美性活一级视频 | 久久中文亚洲国产 | 中文字幕在线观看一区二区 | 欧美精品免费线视频观看视频 | 久久福利资源站免费观看i 久久高清精品 | 中国一级毛片免费观看 | 一级黄片一级毛片 | 一级做a爰片久久毛片潮喷 一级做a爰片久久毛片美女 | 国产精品一在线观看 | www日本高清视频 | 国产一二三区视频 | 精品欧美成人高清在线观看2021 | 萌白酱在线喷水福利视频 |