• Mybatisplus 常用注解


    一、Mybatisplus 注解

    @TableName 

    表名注解,标识实体类对应的表

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
    4. public @interface TableName {
    5. // 表名
    6. String value() default "";
    7. // schema
    8. String schema() default "";
    9. // 是否保持使用全局的 tablePrefix 的值(当全局 tablePrefix 生效时)
    10. boolean keepGlobalPrefix() default false;
    11. // xml 中 resultMap 的 id(用于满足特定类型的实体类对象绑定)
    12. String resultMap() default "";
    13. // 是否自动构建 resultMap 并使用(如果设置 resultMap 则不会进行 resultMap 的自动构建与注入)
    14. boolean autoResultMap() default false;
    15. // 需要排除的属性名
    16. String[] excludeProperty() default {};
    17. }

    @TableId

    主键注解

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface TableId {
    5. // 主键字段名
    6. String value() default "";
    7. // 指定主键类型
    8. IdType type() default IdType.NONE;
    9. }
    10. public enum IdType {
    11. // AUTO 数据库 ID 自增
    12. AUTO(0),
    13. // NONE 无状态,该类型为未设置主键类型(注解里等于跟随全局,全局里约等于 INPUT)
    14. NONE(1),
    15. // INPUT insert 前自行 set 主键值
    16. INPUT(2),
    17. // ASSIGN_ID 分配 ID(主键类型为 Number(Long 和 Integer)或 String)(since 3.3.0),使用接口IdentifierGenerator的方法nextId(默认实现类为DefaultIdentifierGenerator雪花算法)
    18. ASSIGN_ID(3),
    19. // ASSIGN_UUID 分配 UUID,主键类型为 String(since 3.3.0),使用接口IdentifierGenerator的方法nextUUID(默认 default 方法)
    20. ASSIGN_UUID(4);
    21. private final int key;
    22. private IdType(int key) {
    23. this.key = key;
    24. }
    25. public int getKey() {
    26. return this.key;
    27. }
    28. }

    @TableField 

    字段注解(非主键)

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface TableField {
    5. // 数据库字段名
    6. String value() default "";
    7. // 是否为数据库表字段
    8. boolean exist() default true;
    9. // 字段 where 实体查询比较条件,有值设置则按设置的值为准,没有则为默认全局的 %s=#{%s}
    10. String condition() default "";
    11. // 字段 update set 部分注入,例如:当在version字段上注解update="%s+1" 表示更新时会 set version=version+1 (该属性优先级高于 el 属性)
    12. String update() default "";
    13. // FieldStrategy
    14. FieldStrategy insertStrategy() default FieldStrategy.DEFAULT;
    15. // FieldStrategy
    16. FieldStrategy updateStrategy() default FieldStrategy.DEFAULT;
    17. // FieldStrategy
    18. FieldStrategy whereStrategy() default FieldStrategy.DEFAULT;
    19. // 字段自动填充策略
    20. FieldFill fill() default FieldFill.DEFAULT;
    21. // 是否进行 select 查询
    22. boolean select() default true;
    23. // 是否保持使用全局的 format 进行处理
    24. boolean keepGlobalFormat() default false;
    25. String property() default "";
    26. // JDBC 类型 (该默认值不代表会按照该值生效)
    27. JdbcType jdbcType() default JdbcType.UNDEFINED;
    28. // 类型处理器 (该默认值不代表会按照该值生效)
    29. Classextends TypeHandler> typeHandler() default UnknownTypeHandler.class;
    30. boolean javaType() default false;
    31. // 指定小数点后保留的位数
    32. String numericScale() default "";
    33. }
    34. public enum FieldStrategy {
    35. // 忽略判断
    36. IGNORED,
    37. // 非 NULL 判断
    38. NOT_NULL,
    39. // 非空判断(只对字符串类型字段,其他类型字段依然为非 NULL 判断)
    40. NOT_EMPTY,
    41. // 追随全局配置
    42. DEFAULT,
    43. // 不加入SQL
    44. NEVER;
    45. private FieldStrategy() {
    46. }
    47. }
    48. public enum FieldFill {
    49. // 默认不处理
    50. DEFAULT,
    51. // 插入时填充字段
    52. INSERT,
    53. // 更新时填充字段
    54. UPDATE,
    55. // 插入和更新时填充字段
    56. INSERT_UPDATE;
    57. private FieldFill() {
    58. }
    59. }

    @Version

    乐观锁注解、标记 @Version 在字段上

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface Version {
    5. }

    @EnumValue

    普通枚举类注解(注解在枚举字段上)

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface EnumValue {
    5. }

    @TableLogic

    表字段逻辑处理注解(逻辑删除)

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface TableLogic {
    5. // 逻辑未删除值
    6. String value() default "";
    7. // 逻辑删除值
    8. String delval() default "";
    9. }

    @OrderBy

    内置 SQL 默认指定排序,优先级低于 wrapper 条件查询

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
    4. public @interface OrderBy {
    5. // 是否倒序查询
    6. boolean asc() default false;
    7. /** @deprecated */
    8. @Deprecated
    9. boolean isDesc() default true;
    10. // 数字越小越靠前
    11. short sort() default 32767;
    12. }

    二、Mybatits注解
     

    @Select

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.METHOD})
    4. @Repeatable(Select.List.class)
    5. public @interface Select {
    6. String[] value();
    7. String databaseId() default "";
    8. @Documented
    9. @Retention(RetentionPolicy.RUNTIME)
    10. @Target({ElementType.METHOD})
    11. public @interface List {
    12. Select[] value();
    13. }
    14. }

    @Delete

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.METHOD})
    4. @Repeatable(Delete.List.class)
    5. public @interface Delete {
    6. String[] value();
    7. String databaseId() default "";
    8. @Documented
    9. @Retention(RetentionPolicy.RUNTIME)
    10. @Target({ElementType.METHOD})
    11. public @interface List {
    12. Delete[] value();
    13. }
    14. }

    @Insert

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.METHOD})
    4. @Repeatable(Insert.List.class)
    5. public @interface Insert {
    6. String[] value();
    7. String databaseId() default "";
    8. @Documented
    9. @Retention(RetentionPolicy.RUNTIME)
    10. @Target({ElementType.METHOD})
    11. public @interface List {
    12. Insert[] value();
    13. }
    14. }

    @Update

    1. @Documented
    2. @Retention(RetentionPolicy.RUNTIME)
    3. @Target({ElementType.METHOD})
    4. @Repeatable(Update.List.class)
    5. public @interface Update {
    6. String[] value();
    7. String databaseId() default "";
    8. @Documented
    9. @Retention(RetentionPolicy.RUNTIME)
    10. @Target({ElementType.METHOD})
    11. public @interface List {
    12. Update[] value();
    13. }
    14. }

    @Mapper

    1. @Documented
    2. @Inherited
    3. @Retention(RetentionPolicy.RUNTIME)
    4. @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
    5. public @interface Mapper {
    6. }


    MyBatis-Plus 官网地址

    MyBatis中文网

  • 相关阅读:
    【uniapp】 video视频层级、遮挡其他弹窗或顶部导航 使用nvue覆盖
    UE4 材质学习 (06-LandscapeLayerBlend地形节点的应用例子)
    关于请求和重定向的路径问题
    Polygon zkEVM zkASM 与 以太坊虚拟机opcode 对应集合
    三部曲深剖C++类与对象——下篇
    java毕业生设计中小型连锁超市配送中心配送管理计算机源码+系统+mysql+调试部署+lw
    数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
    【提示学习论文】BlackVIP: Black-Box Visual Prompting for Robust Transfer Learning论文原理
    Java on VS Code 8月更新|反编译器用户体验优化、新 Maven 项目工作流、代码高亮稳定性提升
    阿里拆了中台,中台还有未来吗?
  • 原文地址:https://blog.csdn.net/qq_34253002/article/details/133989663