当前位置:网站首页>Commonly used built-in methods of mybtis plus
Commonly used built-in methods of mybtis plus
2022-07-27 18:38:00 【Programmer seven seven】
1 Insert method
1.1 save()
Insert a single piece of data .
/**
* Use the built-in method save( Insert )
*
* @return
*/
@PostMapping("/save")
public boolean save(@RequestBody UserEntity userEntity) {
return userService.save(userEntity);
}1.2 saveBatch()
Bulk insert data .
/**
* Use the built-in method saveBatch( Insert )
*
* @return
*/
@PostMapping("/saveBatch")
public boolean saveBatch(@RequestBody List<UserEntity> userList) {
return userService.saveBatch(userList);
}2 Update method
2.1 updateById()
Update single data .
/**
* Use the built-in method updateById( to update )
*
* @return
*/
@PostMapping("/updateById")
public boolean updateById(@RequestBody UserEntity userEntity) {
return userService.updateById(userEntity);
}2.2 updateBatchById()
Batch update data .
/**
* Use the built-in method updateBatchById( to update )
*
* @return
*/
@PostMapping("/updateBatchById")
public boolean updateBatchById(@RequestBody List<UserEntity> userList) {
return userService.updateBatchById(userList);
}3 Insert or update method
3.1 saveOrUpdate()
Insert or update a single piece of data .
/**
* Use the built-in method saveOrUpdate( Insert or update )
*
* @return
*/
@PostMapping("/saveOrUpdate")
public boolean saveOrUpdate(@RequestBody UserEntity userEntity) {
return userService.saveOrUpdate(userEntity);
}3.2 saveOrUpdateBatch()
Batch insert or update data .
/**
* Use the built-in method saveOrUpdateBatch( Insert or update )
*
* @return
*/
@PostMapping("/saveOrUpdateBatch")
public boolean saveOrUpdateBatch(@RequestBody List<UserEntity> userList) {
return userService.saveOrUpdateBatch(userList);
}4 Delete method
4.1 removeById()
Delete single data .
/**
* Use the built-in method removeById( Delete )
*
* @return
*/
@DeleteMapping("/removeById/{username}")
public boolean removeById(@PathVariable("username") String username) {
return userService.removeById(username);
}4.2 removeByIds()
Batch deletion of data .
/**
* Use the built-in method removeByIds( Delete )
*
* @return
*/
@DeleteMapping("removeByIds")
public boolean removeByIds(@RequestBody List<String> usernameList) {
return userService.removeByIds(usernameList);
}5 Query data
5.1 list()
Query list data according to specified conditions , The return data type is entity class type .
/**
* Use the built-in method list( Inquire about )
*
* @return
*/
@GetMapping("list")
public List<UserEntity> list() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.list(queryWrapper);
}5.2 listMaps()
Query list data according to specified conditions , The return data type is Map type .
/**
* Use the built-in method listMaps( Inquire about )
*
* @return
*/
@GetMapping("listMaps")
public List<Map<String, Object>> listMaps() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.listMaps(queryWrapper);
}5.3 listObjs()
Query list data according to specified conditions , The return data type is Object type .
/**
* Use the built-in method listObjs( Inquire about )
*
* @return
*/
@GetMapping("listObjs")
public List<Object> listObjs() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.listObjs(queryWrapper);
}5.4 listByIds()
Query list data according to the primary key list , The return data type is entity class type .
/**
* Use the built-in method listByIds( Inquire about )
*
* @return
*/
@GetMapping("listByIds")
public List<UserEntity> listByIds() {
return userService.listByIds(new ArrayList<>(Arrays.asList("123")));
}5.5 listByMap()
Query list data according to specified conditions , The return data type is entity class type .
/**
* Use the built-in method listByMap( Inquire about )
*
* @return
*/
@GetMapping("listByMap")
public List<UserEntity> listByMap() {
Map<String, Object> columnMap = new HashMap<>();
columnMap.put("username", "123");
return userService.listByMap(columnMap);
}5.6 getById()
Query a single piece of data according to the primary key , The return data type is entity class type .
/**
* Use the built-in method getById( Inquire about )
*
* @return
*/
@GetMapping("getById")
public UserEntity getById() {
return userService.getById("123");
}5.7 getOne()
Query a single piece of data according to the specified conditions , The return data type is entity class type .
/**
* Use the built-in method getOne( Inquire about )
*
* @return
*/
@GetMapping("getOne")
public UserEntity getOne() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.getOne(queryWrapper);
}5.8 getMap()
Query a single piece of data according to the specified conditions , The return data type is Map type .
/**
* Use the built-in method getMap( Inquire about )
*
* @return
*/
@GetMapping("getMap")
public Map<String, Object> getMap() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.getMap(queryWrapper);
}5.9 count()
Query the number of records according to the specified conditions .
/**
* Use the built-in method count( Inquire about )
*
* @return
*/
@GetMapping("count")
public int count() {
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.count(queryWrapper);
}5.10 page()
Query the data according to the specified conditions and page , The return data type is entity class type .
/**
* Use the built-in method page( Inquire about )
*
* @return
*/
@GetMapping("page")
public Page<UserEntity> page() {
Page<UserEntity> page = new Page<>(1, 10);
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.page(page, queryWrapper);
}5.11 page
/**
* Use the built-in method pageMaps( Inquire about )
*
* @return
*/
@GetMapping("pageMaps")
public Page<Map<String, Object>> pageMaps() {
Page<Map<String, Object>> page = new Page<>(1, 10);
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.pageMaps(page, queryWrapper);
}Maps()
Query the data according to the specified conditions and page , The return data type is Map type .
/**
* Use the built-in method pageMaps( Inquire about )
*
* @return
*/
@GetMapping("pageMaps")
public Page<Map<String, Object>> pageMaps() {
Page<Map<String, Object>> page = new Page<>(1, 10);
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(UserEntity::getUsername, "123");
return userService.pageMaps(page, queryWrapper);
}notes :
of MyBatis-Plus Please check the following blog for the configuration of .
边栏推荐
- XML学习 Day1 : xml / Jsoup解析器 / selector选择器 /Xpath选择器
- [MIT 6.S081] Lec 8: Page faults 笔记
- [MIT 6.S081] Lab 3: page tables
- 技术分享| 快对讲综合调度系统
- 阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统
- Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
- 1. opencv图片基础操作
- 虚拟偶像的歌声原来是这样生成的!
- [MIT 6.S081] Lab 11: networking
- Deep learning: a survey of behavior recognition
猜你喜欢
![[MIT 6.S081] Lab 9: file system](/img/f5/ea30b1fe5b6d73c86f2509c690ca20.png)
[MIT 6.S081] Lab 9: file system

Lotcode dynamic array exercise (724118766)

2021.8.1 notes DBA
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)
[MIT 6.S081] Lab 4: traps

机器学习分类任务效果评估指标大全(包含ROC和AUC)
![[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6](/img/ca/e8c0827b13805c7c74cc41bf84c6ff.png)
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6

MySQL 主从复制数据不一致,怎么办?
![[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6](/img/ca/e8c0827b13805c7c74cc41bf84c6ff.png)
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6

Random talk on GIS data (V) - geographic coordinate system
![[MIT 6.S081] Lab 5: xv6 lazy page allocation](/img/f6/8b619412bc6ba425d0f04629917e80.png)
[MIT 6.S081] Lab 5: xv6 lazy page allocation
随机推荐
2021.8.6 notes jsoup
微信小程序多文件上传
Preliminary introduction to C miscellaneous lecture linked list
Software installation related
[MIT 6.S081] Lab 3: page tables
2021.8.7笔记 servlet
Zhanrui fresh seedlings: enable full scene applications, and massive data needs the integration of AI and IOT
[MIT 6.S081] Lab 11: networking
Binary tree concept
uniapp 在app端page选择器没有效果
mysql视图基本操作
技术分享| 快对讲综合调度系统
Machine learning -- error caused by only one kind of label data in SVM training set
Jianan Yunzhi has completed the pre roadshow and is expected to land on NASDAQ on November 20
超实用!阿里P9私藏的Kubernetes学习笔记,看完直呼NB
2021.7.18笔记 mysql数据类型
2021.7.13 note sub query
Deep learning: stgcn learning notes
The end of another era!
JDBC learning day1:jdbc