Data CRUD
# Mapper CRUD interface
description
-universal CRUD encapsulation [basesmapper] (https://gitee.com/dromara/Easy-Es/blob/master/easy-es-core/src/main/Java/cn/easy es/core/conditions/interfaces/basesmapper.java) interface, which is easy-.
-Generic T is an arbitrary entity object.
The-insert interface needs to be different from MP. See the insert document below for details.
-the parameter Serializable is any type of primary key. Easy-Es does not recommend using composite primary keys. Each index has its own unique id primary key.
-The object Wrapper is a conditional constructor
-For the get' and
set' methods in the entity object T, we recommend that you use the [lombok] (https://projectlombok.org/) plug-in to generate the field names. If you use the plug-in that comes with IDEA, some fields named by hump will not get the correct field names.
For example, there is a field name named eName, and the get method generated by Lombok is getEName (), but the get method generated by IDEA is geteName (), so the bottom layer of the framework will report an error when parsing the field name, and MP also has the same problem.
# Insert
# Insert
//Insert a record, which is inserted into the index corresponding to the current mapper by default.
Integer insert(T entity);
//Insert a record and specify the specific route to be inserted.
Integer insert(String routing, T entity);
// Parent-child type inserts a record, route can be specified, parent id
Integer insert(String routing, String parentId, T entity);
//Insert data. You can specify the specific index to insert. Multiple ones are separated by commas.
Integer insert(T entity, String... indexNames);
//Insert data, routing and multi-index insertion can be specified
Integer insert(String routing, T entity, String... indexNames);
// Parent-child type inserts data, you can specify routing, parent id and multi-index insertion
Integer insert(String routing, String parentId, T entity, String... indexNames);
//Insert multiple records in batches
Integer insertBatch(Collection<T> entityList)
// Batch insertion can specify routing
Integer insertBatch(String routing, Collection<T> entityList);
// Parent-child type batch insertion can specify routing, parent id
Integer insertBatch(String routing, String parentId, Collection<T> entityList);
// Insert multiple records in batches. You can specify the specific index to insert. Multiple records are separated by commas.
Integer insertBatch(Collection<T> entityList, String... indexNames);
// Batch insertion can specify routing and multiple indexes
Integer insertBatch(String routing, Collection<T> entityList, String... indexNames);
// Parent-child type batch insertion can specify routing, parent ID and multiple indexes
Integer insertBatch(String routing, String parentId, Collection<T> entityList, String... indexNames);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
String | routing | routing |
String | indexNames | Index list |
T | entity | Entity object |
Collection<T> | entityList | collection of entity objects |
pay special attention
-If the entity you passed in at the time of insert has an id and the data corresponding to the id already exists, the actual effect of this insert is to update the data corresponding to the id, and the update is not included in the total number of successful entries returned by the insert interface. -When the data update logic is triggered by the insert interface as described above, the updated fields and globally configured policies (such as NOT_NULL/NOT_EMPTY) will not take effect. If you want the policies to take effect, you can call the Update interface instead of the insert interface. -If you need an id value after insertion, you can get it directly from entity, and the usage is the same as that in MP. For batch insertion, you can also get the successfully inserted data id directly from the original object. The above interface returns Integer as the number of successful entries.
//Delete based on ID
Integer deleteById(Serializable id);
//Delete based on ID and specify the route
Integer deleteById(String routing, Serializable id);
//Delete based on ID. Specific indexes can be specified. Multiple ones are separated by commas.
Integer deleteById(Serializable id, String... indexNames);
// Delete based on ID. Routing and multiple indexes can be specified.
Integer deleteById(String routing, Serializable id, String... indexNames);
//Delete records based on entity conditions
Integer delete(LambdaEsQueryWrapper<T> wrapper);
// Delete (batch delete based on ID)
Integer deleteBatchIds(Collection<? extends Serializable> idList);
// Deletion (batch deletion based on ID) can specify the route
Integer deleteBatchIds(String routing, Collection<? extends Serializable> idList);
// Deletion (batch deletion based on ID) can specify specific indexes, and separate multiple ones with commas.
Integer deleteBatchIds(Collection<? extends Serializable> idList, String... indexNames);
// Delete (batch delete based on ID) Routing and multiple indexes can be specified
Integer deleteBatchIds(String routing, Collection<? extends Serializable> idList, String... indexNames);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
String | routing | routing |
String | indexNames | Index list |
Wrapper<T> | queryWrapper | Entity Wrapper Class QueryWrapper |
Serializable | id | Primary key ID |
Collection<? Extends Serializable> | idList | Primary key ID list |
# Update
//Update based on ID
Integer updateById(T entity);
//Update based on ID to specify the route
Integer updateById(String routing, T entity);
//Update based on ID. Specific indexes can be specified. Multiple ones are separated by commas.
Integer updateById(T entity, String... indexNames);
//Update based on ID, routing and multiple indexes can be specified
Integer updateById(String routing, T entity, String... indexNames);
//Batch update based on ID
Integer updateBatchByIds(Collection<T> entityList);
//Batch update based on ID, route can be specified
Integer updateBatchByIds(String routing, Collection<T> entityList);
//Batch update based on ID. Specific indexes can be specified. Multiple ones are separated by commas.
Integer updateBatchByIds(Collection<T> entityList, String... indexNames);
//Batch update based on ID, routing and multiple indexes can be specified
Integer updateBatchByIds(String routing, Collection<T> entityList, String... indexNames);
//Update records based on dynamic conditions
Integer update(T entity, LambdaEsUpdateWrapper<T> updateWrapper);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
String | routing | routing |
String | indexNames | Index list |
T | entity | Entity object |
Wrapper<T> | updateWrapper | Entity object encapsulation operation class UpdateWrapper |
Collection<T> | entityList | collection of entity objects |
# Select
// 获取总数
Long selectCount(LambdaEsQueryWrapper<T> wrapper);
// 获取总数 distinct为是否去重 若为ture则必须在wrapper中指定去重字段
Long selectCount(Wrapper<T> wrapper, boolean distinct);
// 根据 ID 查询
T selectById(Serializable id);
// 根据 ID 查询 可指定路由
T selectById(String routing, Serializable id);
// 根据 ID 查询 可指定具体的索引,多个用逗号隔开
T selectById(Serializable id, String... indexNames);
// 根据 ID 查询 可指定路由及多索引
T selectById(String routing, Serializable id, String... indexNames);
// 查询(根据ID 批量查询)
List<T> selectBatchIds(Collection<? extends Serializable> idList);
// 查询(根据ID 批量查询) 可指定路由
List<T> selectBatchIds(String routing, Collection<? extends Serializable> idList);
// 查询(根据ID 批量查询)可指定具体的索引,多个用逗号隔开
List<T> selectBatchIds(Collection<? extends Serializable> idList, String... indexNames);
// 查询(根据ID 批量查询) 可指定路由及多索引
List<T> selectBatchIds(String routing, Collection<? extends Serializable> idList, String... indexNames);
// 根据动态查询条件,查询一条记录 若存在多条记录 会报错
T selectOne(LambdaEsQueryWrapper<T> wrapper);
// 根据动态查询条件,查询全部记录
List<T> selectList(LambdaEsQueryWrapper<T> wrapper);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
String | routing | routing |
String | indexNames | Index list |
Wrapper<T> | queryWrapper | Entity Wrapper Class QueryWrapper |
Serializable | id | Primary key ID |
Collection<? Extends Serializable> | idList | Primary key ID list |
提示
The usage of-CRUD interface is basically the same as MP. -The Mapper that users need to inherit is BaseMapper, not BaseMapper. -EE does not provide a Service layer, but sinks some methods of the Service layer in MP directly to the Mapper layer, which will be more convenient for users to use.