CRUD
# Mapper CRUD interface
Description
- Generic CRUD wrapper [BaseEsMapper](https://gitee.com/dromara/easy-es/blob/master/easy-es-core/src/main/java/cn/easyes/core/conditions/interfaces/BaseEsMapper. java) interface, which automatically resolves the entity-object-relationship mapping for Easy-Es startup and converts it to EE internal object injection container
- the generic type T is any entity object
- The insert interface needs to be different from MP. For details, see the insert document below
- The parameter Serializable is any type of primary key. Easy-Es does not recommend using composite primary key convention. Each index has its own unique id primary key
- Object Wrapper as conditional constructor
- For the
get and set
methods in the entity object T, we recommend that you use the Lombok (opens new window) plug-in to generate, if you use IDEA's built-in plug-in to generate the field names obtained in Lambda style , it will cause some fields named in camel case to fail to obtain the correct field name. For example, there is a field name called eName, the get method generated by Lombok is getEName(), but IDEA generates geteName(), so an error will be reported when the underlying framework parses the field name, and MP also has the same problem.
# Insert
// insert a record
Integer insert(T entity);
// batch insert multiple records
Integer insertBatch(Collection<T> entityList)
1
2
3
4
5
2
3
4
5
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
T | entity | entity object |
Collection<T> | entityList | collection of entity objects |
Tips
- If the entity you passed in when inserting 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 counted in the total number of successful entries returned by the insert interface.
- When the insert interface as described above triggers the data update logic, the updated fields and globally configured policies (such as NOT_NULL/NOT_EMPTY) will not take effect. If you expect the policy to take effect, you can call the update interface instead of the insert interface
- After inserting, if you need the id value, you can directly get the id value from the entity. The usage is the same as that in MP. Batch inserting can also directly get the data id after successful insertion from the original object. The above interface returns Integer as the number of successful entries.
# Delete
// delete by ID
Integer deleteById(Serializable id);
// According to the entity condition, delete the record
Integer delete(LambdaEsQueryWrapper<T> wrapper);
// delete (batch delete according to ID)
Integer deleteBatchIds(Collection<? extends Serializable> idList);
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
Wrapper<T> | queryWrapper | Entity wrapper class QueryWrapper |
Serializable | id | primary key ID |
Collection<? extends Serializable> | idList | Primary key ID list |
# Update
//update according to ID
Integer updateById(T entity);
// batch update by ID
Integer updateBatchByIds(Collection<T> entityList);
// Update records based on dynamic conditions
Integer update(T entity, LambdaEsUpdateWrapper<T> updateWrapper);
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
T | entity | entity object |
Wrapper<T> | updateWrapper | Entity object encapsulation operation class UpdateWrapper |
Collection<T> | entityList | collection of entity objects |
# Select
// get the total
Long selectCount(LambdaEsQueryWrapper<T> wrapper);
// query by ID
T selectById(Serializable id);
// Query (batch query based on ID)
List<T> selectBatchIds(Collection<? extends Serializable> idList);
// According to the dynamic query conditions, query a record if there are multiple records, an error will be reported
T selectOne(LambdaEsQueryWrapper<T> wrapper);
// According to dynamic query conditions, query all records
List<T> selectList(LambdaEsQueryWrapper<T> wrapper);
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# Parameter Description
Type | Parameter Name | Description |
---|---|---|
Wrapper<T> | queryWrapper | Entity wrapper class QueryWrapper |
Serializable | id | primary key ID |
Collection<? extends Serializable> | idList | Primary key ID list |
Tips
- CRUD interface usage is basically the same as MP
- The Mapper that users need to inherit is BaseEsMapper instead of BaseMapper
- EE does not provide a Service layer, but directly sinks some of the Service layer methods in MP to the Mapper layer, which will be more convenient for users to use
Help us improve this document (opens new window)
Last update: 2024/03/29