|
1 | | -# Annotation |
| 1 | +# Annotation |
| 2 | + |
| 3 | +> It's about the annotations in `MybatisPlus` (For more details, pls refer to the source code) |
| 4 | + |
| 5 | +Packages: |
| 6 | + |
| 7 | +👉 [mybatis-plus-annotation](https://gitee.com/baomidou/mybatis-plus/tree/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation) |
| 8 | + |
| 9 | +## [@TableName](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/TableName.java) |
| 10 | +- Description:annotation for DB table name |
| 11 | + |
| 12 | +| Properties | Type | Required | Default val | Description | |
| 13 | +| :-: | :-: | :-: | :-: | --- | |
| 14 | +| value | String | N | "" | DB table name | |
| 15 | +| resultMap | String | N | "" | resultMap id in *mapper.xml | |
| 16 | +| schema | String | N | "" | schema(@since 3.1.1) | |
| 17 | +| keepGlobalPrefix | boolean | N | false | true: keep using the tablePrefix in Global Configuration(if tablePrefix configurated in Global, will set the Global value here automatically)(@since 3.1.1) | |
| 18 | + |
| 19 | + |
| 20 | +## [@TableId](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/TableId.java) |
| 21 | +- Description:annotation for Primary Key |
| 22 | + |
| 23 | +| Properties | Type | Required | Default val | Description | |
| 24 | +| :-: | :-: | :-: | :-: | :-: | |
| 25 | +| value | String | N | "" | column name of the PK, if java entity propertyName is "id", will be recognized as PK | |
| 26 | +| type | Enum | N | IdType.NONE | PK type(e.g. AUTO, UUID, ID_WORKER, INPUT) | |
| 27 | + |
| 28 | +#### [IdType](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/IdType.java) |
| 29 | + |
| 30 | +| Val | Descp | |
| 31 | +| :-: | :-: | |
| 32 | +| AUTO | autoincrement by DB | |
| 33 | +| INPUT | user specify manually | |
| 34 | +| ID_WORKER | distributed union ID, Long type | |
| 35 | +| UUID | UUID String with length of 32 | |
| 36 | +| NONE | nothing | |
| 37 | +| ID_WORKER_STR | String value of ID_WORKER | |
| 38 | + |
| 39 | + |
| 40 | +## [@TableField](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/TableField.java) |
| 41 | +- Description:annotation for column(non-PK) |
| 42 | + |
| 43 | +| Properties | Type | Required | Default val | Description | |
| 44 | +| :-: | :-: | :-: | :-: | :-: | |
| 45 | +| value | String | N | "" | column name | |
| 46 | +| el | String | N | "" | Mapped to `#{ ... }` for native, equivalently write `#{ ... }` in *mapper.xml | |
| 47 | +| exist | boolean | N | true | false: NOT a column, just temporary property | |
| 48 | +| condition | String | N | "" | config the expression in where condition, by default it's `%s=#{%s}`, [reference](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/SqlCondition.java) | |
| 49 | +| update | String | N | "" | e.g. value="version", update="%s+1", when do update, 'version=version+1' will be appended to `update xx_table set xxx=xxx` (this property has higher priority than `el` ) | |
| 50 | +| insertStrategy | Enum | N | FieldStrategy.DEFAULT | specify the strategy of this column when do insert, e.g. NOT_NULL: insert into table_a(<if test="columnProperty != null">column</if>) values (<if test="columnProperty != null">#{columnProperty}</if>);(since v_3.1.2) | |
| 51 | +| updateStrategy | Enum | N | FieldStrategy.DEFAULT | specify the strategy of this column when do update, e.g. IGNORED: update table_a set column=#{columnProperty};(since v_3.1.2) | |
| 52 | +| whereStrategy | Enum | N | FieldStrategy.DEFAULT | specify the strategy of this column when do query, e.g. NOT_EMPTY: where <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>;(since v_3.1.2) | |
| 53 | +| fill | Enum | N | FieldFill.DEFAULT | auto fill strategy: INSERT, UPDATE, INSERT_UPDATE | |
| 54 | +| select | boolean | N | true | false: this column will not appear in select expression | |
| 55 | +| keepGlobalFormat | boolean | N | false | whether keep the Global column name format(e.g. UnderscoreToCamelCase) (@since 3.1.1) | |
| 56 | + |
| 57 | +#### [FieldStrategy](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/FieldStrategy.java) |
| 58 | + |
| 59 | +| Val | Descp | |
| 60 | +| :-: | :-: | |
| 61 | +| IGNORED | ignored | |
| 62 | +| NOT_NULL | <if test="columnProperty != null">xxx</if> | |
| 63 | +| NOT_EMPTY | <if test="columnProperty != null and columnProperty!=''">(only support String column, for other types, will processed as NOT_NULL) | |
| 64 | +| DEFAULT | keep the Global config | |
| 65 | + |
| 66 | +#### [FieldFill](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/FieldFill.java) |
| 67 | + |
| 68 | +| Val | Descp | |
| 69 | +| :-: | :-: | |
| 70 | +| DEFAULT | bypass | |
| 71 | +| INSERT | fill the column when do insert(should specify the filled value in MetaObjectHandler) | |
| 72 | +| UPDATE | fill the column when do update | |
| 73 | +| INSERT_UPDATE | fill the column when do both insert/update | |
| 74 | + |
| 75 | +## [@Version](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/Version.java) |
| 76 | +- Description:annotation for Optimistic Lock, drop `@Verison` on the version property |
| 77 | + |
| 78 | + |
| 79 | +## [@EnumValue](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/EnumValue.java) |
| 80 | +- Description:annotation for enum property, to specify the real column value, and map to enum property |
| 81 | + |
| 82 | + |
| 83 | +## [@TableLogic](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/TableLogic.java) |
| 84 | + |
| 85 | +- Description:annotation to specify the Logic delete column |
| 86 | + |
| 87 | +| Properties | Type | Required | Defalut val | Description | |
| 88 | +| :-: | :-: | :-: | :-: | :-: | |
| 89 | +| value | String | N | "" | value for non-deleted records | |
| 90 | +| delval | String | N | "" | value for deleted records | |
| 91 | + |
| 92 | + |
| 93 | +## [@SqlParser](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/SqlParser.java) |
| 94 | + |
| 95 | +- Description:annotation for tenant (annotation for mapper is supportted since 3.1.1) |
| 96 | + |
| 97 | +| Properties | Type | Required | Default Val | Description | |
| 98 | +| :-: | :-: | :-: | :-: | :-: | |
| 99 | +| filter | boolean | N | false | true: bypass ISqlParser.doFilter(), otherwise sql will be parsed in ISqlParser chain and append addition conditions such as tenant_id, etc. | |
| 100 | + |
| 101 | + |
| 102 | +## [@KeySequence](https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/KeySequence.java) |
| 103 | + |
| 104 | +- Description:use DB sequence as PK, such as `oracle`.sequence |
| 105 | + |
| 106 | +| Properties | Type | Required | Defalut val | Description | |
| 107 | +| :-: | :-: | :-: | :-: | :-: | |
| 108 | +| value | String | Y | "" | sequence name | |
| 109 | +| clazz | Class | N | String.class | return value type, if String.class, will return Number.toString: "1" | |
0 commit comments