MyBatis Plus Mapper CRUD接口測試方式
MyBatis Plus Mapper CRUD接口測試
插入
插入一條記錄
int insert(T entity);
刪除
根據(jù)主鍵ID刪除,主鍵ID支持String、Number類型
int deleteById(Serializable id);
根據(jù)主鍵ID批量刪除
int deleteBatchIds(Collection<? extends Serializable> idList);
根據(jù)條件進(jìn)行刪除。原理為SQL語句拼接,因此Map中需要傳輸數(shù)據(jù)庫字段列
實質(zhì)為 delete from 表 where 【key1 = value1】 AND 【key2 = value2】
【key1-value1】【key2-value2】為Map的鍵值對
int deleteByMap(Map<String, Object> columnMap);
更新
根據(jù)ID更新。null值忽略。
Employee employee = new Employee();
employee.setId(7);
employee.setLastName("a");
employee.setAge(23);
employee.setEmail(null);
employee.setGender(null);
mapper.updateById(employee);
UPDATE tb_employee SET last_name='a', age=23
WHERE id=7;根據(jù)條件更新,null值忽略。
Employee employee = new Employee();
employee.setId(7L);
employee.setLastName("c");
//這里設(shè)置的null,就是說不操作email字段
employee.setEmail(null);
employee.setGender(null);
employee.setAge(23);
mapper.update(employee, new UpdateWrapper<Employee>().lambda()
.eq(Employee::getId, 7)
);
UPDATE tb_employee SET last_name='c', age=23
WHERE (id = 7);定制置空。
Employee employee = new Employee();
employee.setId(7L);
employee.setLastName("c");
//這里設(shè)置的null,就是說不操作email字段
employee.setEmail(null);
employee.setGender(null);
employee.setAge(23);
mapper.update(employee, new UpdateWrapper<Employee>().lambda()
.eq(Employee::getId, 7)
//這里可以定制置空SQL
.set(Employee::getEmail,null)
.set(Employee::getGender,"")
);
UPDATE tb_employee SET last_name='c', age=23, email=null,gender=''
WHERE (id = 7);總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
mybatis-plus通用枚舉@JsonValue接收參數(shù)報錯No enum constant
最近在使用mybatis-plus時用到了通用枚舉,遇到了問題,本文主要介紹了mybatis-plus通用枚舉@JsonValue接收參數(shù)報錯No enum constant,具有一定的參考價值,感興趣的可以了解一下2023-09-09
Spring中的ContextLoaderListener詳細(xì)解析
這篇文章主要介紹了Spring中的ContextLoaderListener詳細(xì)解析,在web容器即Tomact容器啟動web應(yīng)用即servlet應(yīng)用時,會觸發(fā)ServletContextEvent時間,這個事件會被ServletContextListener監(jiān)聽,需要的朋友可以參考下2023-12-12
Kotlin 內(nèi)聯(lián)函數(shù)詳解及實例
這篇文章主要介紹了Kotlin 內(nèi)聯(lián)函數(shù)詳解及實例的相關(guān)資料,需要的朋友可以參考下2017-06-06

