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

mybatis-plus中BaseMapper入門使用

 更新時(shí)間:2021年08月17日 11:51:12   作者:大田醬紫  
本文主要介紹了mybatis-plus中BaseMapper入門使用,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

具體教程參考官網(wǎng)文檔: baomidou.com/

入門使用BaseMapper完成增刪改查

根據(jù)數(shù)據(jù)庫表制作相應(yīng)實(shí)體類

@TableName(value = "user")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String name;

    private String password;

    private String username;
    // 省略set,get
    }

創(chuàng)建對(duì)應(yīng)mapper類

public interface UserMapper extends BaseMapper<User> {
 //這里什么都不用寫
}

由于BaseMapper已經(jīng)集成了基礎(chǔ)的增刪改查方法,這里對(duì)應(yīng)的mapper.xml也是不用寫的

添加關(guān)于mapper包的注冊(cè)

@SpringBootApplication
@MapperScan("com.hyx.mybatisplusdemo.mapper")
public class MybatisplusdemoApplication {

 public static void main(String[] args) {
  SpringApplication.run(MybatisplusdemoApplication.class, args);
 }

}

修改配置文件

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql:///test?useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=123456

測(cè)試類

@SpringBootTest
class MybatisplusdemoApplicationTests {

 @Autowired
 UserMapper userMapper;

 @Test
 void contextLoads() {
  
  User user = userMapper.selectById(7l);
  userMapper.deleteById(user);
  System.out.println(user);
 }

}

如果要自定義一些增刪改查方法,可以在配置類中添加:

##mybatis-plus mapper xml 文件地址
mybatis-plus.mapper-locations= classpath*:mapper/*Mapper.xml
##mybatis-plus type-aliases 文件地址
mybatis-plus.type-aliases-package= com.hyx.mybatisplusdemo.entity

然后就與mybatis一樣,創(chuàng)建對(duì)應(yīng)的xml文件,去實(shí)現(xiàn)相應(yīng)的方法就可以了

BaseMapper各方法詳解

Insert

// 插入一條記錄
int insert(T entity);

Delete

// 根據(jù) entity 條件,刪除記錄
int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
// 刪除(根據(jù)ID 批量刪除)
int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// 根據(jù) ID 刪除
int deleteById(Serializable id);
// 根據(jù) columnMap 條件,刪除記錄
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);

Update

// 根據(jù) whereEntity 條件,更新記錄
int update(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper);
// 根據(jù) ID 修改
int updateById(@Param(Constants.ENTITY) T entity);

Select

// 根據(jù) ID 查詢
T selectById(Serializable id);
// 根據(jù) entity 條件,查詢一條記錄
T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

// 查詢(根據(jù)ID 批量查詢)
List<T> selectBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// 根據(jù) entity 條件,查詢?nèi)坑涗?
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 查詢(根據(jù) columnMap 條件)
List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
// 根據(jù) Wrapper 條件,查詢?nèi)坑涗?
List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根據(jù) Wrapper 條件,查詢?nèi)坑涗?。注意?只返回第一個(gè)字段的值
List<Object> selectObjs(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

// 根據(jù) entity 條件,查詢?nèi)坑涗洠ú⒎摚?
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根據(jù) Wrapper 條件,查詢?nèi)坑涗洠ú⒎摚?
IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根據(jù) Wrapper 條件,查詢總記錄數(shù)
Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

到此這篇關(guān)于mybatis-plus中BaseMapper入門使用的文章就介紹到這了,更多相關(guān)mybatis-plus BaseMapper入門內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • spring?boot中spring框架的版本升級(jí)圖文教程

    spring?boot中spring框架的版本升級(jí)圖文教程

    Spring Boot是一款基于Spring框架的快速開發(fā)框架,它提供了一系列的開箱即用的功能和組件,這篇文章主要給大家介紹了關(guān)于spring?boot中spring框架的版本升級(jí)的相關(guān)資料,需要的朋友可以參考下
    2023-10-10
  • java多線程處理執(zhí)行solr創(chuàng)建索引示例

    java多線程處理執(zhí)行solr創(chuàng)建索引示例

    這篇文章主要介紹了java多線程處理執(zhí)行solr創(chuàng)建索引示例,需要的朋友可以參考下
    2014-02-02
  • java web返回中文亂碼問題及解決

    java web返回中文亂碼問題及解決

    這篇文章主要介紹了java web返回中文亂碼問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Java聊天室之使用Socket實(shí)現(xiàn)傳遞對(duì)象

    Java聊天室之使用Socket實(shí)現(xiàn)傳遞對(duì)象

    這篇文章主要為大家詳細(xì)介紹了Java簡(jiǎn)易聊天室之使用Socket實(shí)現(xiàn)傳遞對(duì)象功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以了解一下
    2022-10-10
  • Java中使用opencv的問題

    Java中使用opencv的問題

    這篇文章主要介紹了Java中使用opencv的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • mybatis 如何判斷l(xiāng)ist集合是否包含指定數(shù)據(jù)

    mybatis 如何判斷l(xiāng)ist集合是否包含指定數(shù)據(jù)

    這篇文章主要介紹了mybatis 判斷l(xiāng)ist集合是否包含指定數(shù)據(jù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • SpringCloud Config分布式配置中心使用教程介紹

    SpringCloud Config分布式配置中心使用教程介紹

    springcloud config是一個(gè)解決分布式系統(tǒng)的配置管理方案。它包含了 client和server兩個(gè)部分,server端提供配置文件的存儲(chǔ)、以接口的形式將配置文件的內(nèi)容提供出去,client端通過接口獲取數(shù)據(jù)、并依據(jù)此數(shù)據(jù)初始化自己的應(yīng)用
    2022-12-12
  • Java內(nèi)部類及其特點(diǎn)的講解

    Java內(nèi)部類及其特點(diǎn)的講解

    今天小編就為大家分享一篇關(guān)于Java內(nèi)部類及其特點(diǎn)的講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • 老程序員教你一天時(shí)間完成Java迷宮小游戲

    老程序員教你一天時(shí)間完成Java迷宮小游戲

    最近經(jīng)常在機(jī)房看同學(xué)在玩一個(gè)走迷宮的游戲,比較有趣,自己也用java寫一個(gè)實(shí)現(xiàn)隨機(jī)生成迷宮的算法,其實(shí)就是一個(gè)圖的深度優(yōu)先遍歷算法.
    2021-08-08
  • Java數(shù)據(jù)結(jié)構(gòu)最清晰圖解二叉樹前 中 后序遍歷

    Java數(shù)據(jù)結(jié)構(gòu)最清晰圖解二叉樹前 中 后序遍歷

    樹是一種重要的非線性數(shù)據(jù)結(jié)構(gòu),直觀地看,它是數(shù)據(jù)元素(在樹中稱為結(jié)點(diǎn))按分支關(guān)系組織起來的結(jié)構(gòu),很象自然界中的樹那樣。樹結(jié)構(gòu)在客觀世界中廣泛存在,如人類社會(huì)的族譜和各種社會(huì)組織機(jī)構(gòu)都可用樹形象表示
    2022-01-01

最新評(píng)論