当前位置:网站首页>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 .
边栏推荐
- Binary tree concept
- MySQL学习 Day1 DDL、DML、DQL基础查询
- [MIT 6.S081] Lab 9: file system
- 浅谈AI深度学习的模型训练和推理
- [MIT 6.S081] Lab 9: file system
- Software installation related
- [MIT 6.S081] Lec 3: OS organization and system calls 笔记
- 2021.7.22 note constraints
- uniapp H5跨域问题
- "Who is Huawei" documentary film series landing on BBC: exposing a large number of Ren Zhengfei's unknown experience
猜你喜欢

2021.7.13笔记 子查询

2021.8.7笔记 servlet

阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统

你有没有在MySQL的order by上栽过跟头

2021.7.22笔记 约束

微信小程序获取openId, sessionKey, unionId
![[mit 6.s081] LEC 3: OS organization and system calls notes](/img/34/073d00245eb39844bbe1740f65fe07.png)
[mit 6.s081] LEC 3: OS organization and system calls notes

2 万字 + 30 张图 | 细聊 MySQL undo log、redo log、binlog 有什么用?

MySQL查询列必须和group by字段一致吗?

Deep learning - paper reading: action structural graph convolution network as-gcn
随机推荐
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
Installation and deployment of zabbix6.0
Uniapp has no effect on the page selector on the app side
rsa加解密(兼容微信小程序环境)
Common commands of database 2
2. 改变颜色空间及颜色检测
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6
怎么会不喜欢呢,CI/CD中轻松发送邮件
Deep learning: installation package records
Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
3. opencv几何变换
multi-table query
2021.7.17 notes MySQL other commands
Solution to invalid SQL Server connection to server
2021.8.6笔记 jsoup
C杂讲 链表初讲
2021.7.13 note sub query
微信小程序多文件上传
mysql视图基本操作
[MIT 6.S081] Lec 1: Introduction and examples 笔记