Annotations
This document explains the classes in the MongoPlus
annotation package (for more details, check the source code comments).
Annotation package source code: 👉 mongo-plus-annotation
@CollectionName
- Description: Collection name annotation, marks the collection corresponding to the entity class.
- Usage: On entity class.
java
@CollectionName("sys_user")
public class User {
private Long id;
private String name;
private Long age;
private String email;
}
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
value | String | Yes | "" | Table name |
@ID
- Description: Primary key annotation, points to MongoDB
_id
field. - Usage: On entity primary key field.
java
@CollectionName("sys_user")
public class User {
@ID
private Long id;
private String name;
private Long age;
private String email;
}
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
type | IdTypeEnum | No | IdTypeEnum.OBJECT_ID | Specifies primary key type |
IdTypeEnum
Value | Description |
---|---|
OBJECT_ID | Generates MongoDB native _id |
ASSIGN_UUID | Generates UUID |
ASSIGN_ULID | Generates ULID (higher efficiency than UUID) |
ASSIGN_ID | Assign ID (primary key type Number(Long or Integer) or String) (since 3.3.0), uses IdentifierGenerator.nextId (default implementation DefaultIdentifierGenerator uses Snowflake algorithm) |
@CollectionField
- Description: Field annotation (non-primary key)
java
@CollectionName("sys_user")
public class User {
@ID
private Long id;
@CollectionField("nickname")
private String name;
private Long age;
private String email;
}
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
value | String | No | "" | Database field name |
exist | boolean | No | true | Whether the field exists in DB |
convertCollect | boolean | No | false | If value is an object and target field is a collection, automatically convert object to collection |
fill | FieldFill | No | FieldFill.DEFAULT | Auto-fill strategy |
typeHandler | Class<?> | No | Void.class | Type handler, must implement |
ignoreNull | boolean | No | true | Ignore null properties |
isObjectId | boolean | No | false | Whether it is an ObjectId |
@MongoTransactional
- Description: Declarative transaction annotation, applied to methods to enable transaction control.
@CollectionLogic
- Description: Logical delete annotation, used to customize document logical delete field and ignore logical delete when global logical delete is enabled.
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
value | String | No | "" | Default logical not deleted value (optional, auto get global config) |
delval | String | No | "" | Default logical deleted value (optional, auto get global config) |
delType | LogicDataType | No | DEFAULT | Type of logical delete field |
@IgnoreTenant
- Description: Ignore multi-tenant annotation, has higher priority.
@MongoDs
- Description: Multi-data source annotation.
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
value | String | Yes | "" | Data source name |
dsHandler | Class<?> | No | Void.class | Data source handler, must implement |