Skip to content
广告❤️成为赞助商

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;
}
AttributeTypeRequiredDefaultDescription
valueStringYes""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;
}
AttributeTypeRequiredDefaultDescription
typeIdTypeEnumNoIdTypeEnum.OBJECT_IDSpecifies primary key type

IdTypeEnum

ValueDescription
OBJECT_IDGenerates MongoDB native _id
ASSIGN_UUIDGenerates UUID
ASSIGN_ULIDGenerates ULID (higher efficiency than UUID)
ASSIGN_IDAssign 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;
}
AttributeTypeRequiredDefaultDescription
valueStringNo""Database field name
existbooleanNotrueWhether the field exists in DB
convertCollectbooleanNofalseIf value is an object and target field is a collection, automatically convert object to collection
fillFieldFillNoFieldFill.DEFAULTAuto-fill strategy
typeHandlerClass<?>NoVoid.classType handler, must implement
ignoreNullbooleanNotrueIgnore null properties
isObjectIdbooleanNofalseWhether 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.
AttributeTypeRequiredDefaultDescription
valueStringNo""Default logical not deleted value (optional, auto get global config)
delvalStringNo""Default logical deleted value (optional, auto get global config)
delTypeLogicDataTypeNoDEFAULTType of logical delete field

@IgnoreTenant

  • Description: Ignore multi-tenant annotation, has higher priority.

@MongoDs

  • Description: Multi-data source annotation.
AttributeTypeRequiredDefaultDescription
valueStringYes""Data source name
dsHandlerClass<?>NoVoid.classData source handler, must implement