TableField.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.baomidou.mybatisplus.annotation;
  17. import org.apache.ibatis.mapping.ParameterMapping;
  18. import org.apache.ibatis.mapping.ResultMapping;
  19. import org.apache.ibatis.type.JdbcType;
  20. import org.apache.ibatis.type.TypeHandler;
  21. import org.apache.ibatis.type.UnknownTypeHandler;
  22. import java.lang.annotation.*;
  23. /**
  24. * 表字段标识
  25. *
  26. * @author hubin sjy tantan
  27. * @since 2016-09-09
  28. */
  29. @Documented
  30. @Retention(RetentionPolicy.RUNTIME)
  31. @Target(ElementType.FIELD)
  32. public @interface TableField {
  33. /**
  34. * 字段值(驼峰命名方式,该值可无)
  35. */
  36. String value() default "";
  37. /**
  38. * 是否为数据库表字段
  39. * 默认 true 存在,false 不存在
  40. */
  41. boolean exist() default true;
  42. /**
  43. * 字段 where 实体查询比较条件
  44. * 默认 `=` 等值
  45. */
  46. String condition() default "";
  47. /**
  48. * 字段 update set 部分注入, 该注解优于 el 注解使用
  49. * <p>
  50. * 例1:@TableField(.. , update="%s+1") 其中 %s 会填充为字段
  51. * 输出 SQL 为:update 表 set 字段=字段+1 where ...
  52. * <p>
  53. * 例2:@TableField(.. , update="now()") 使用数据库时间
  54. * 输出 SQL 为:update 表 set 字段=now() where ...
  55. */
  56. String update() default "";
  57. /**
  58. * 字段验证策略之 insert: 当insert操作时,该字段拼接insert语句时的策略
  59. * IGNORED: 直接拼接 insert into table_a(column) values (#{columnProperty});
  60. * NOT_NULL: insert into table_a(<if test="columnProperty != null">column</if>) values (<if test="columnProperty != null">#{columnProperty}</if>)
  61. * NOT_EMPTY: insert into table_a(<if test="columnProperty != null and columnProperty!=''">column</if>) values (<if test="columnProperty != null and columnProperty!=''">#{columnProperty}</if>)
  62. *
  63. * @since 3.1.2
  64. */
  65. FieldStrategy insertStrategy() default FieldStrategy.DEFAULT;
  66. /**
  67. * 字段验证策略之 update: 当更新操作时,该字段拼接set语句时的策略
  68. * IGNORED: 直接拼接 update table_a set column=#{columnProperty}, 属性为null/空string都会被set进去
  69. * NOT_NULL: update table_a set <if test="columnProperty != null">column=#{columnProperty}</if>
  70. * NOT_EMPTY: update table_a set <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  71. *
  72. * @since 3.1.2
  73. */
  74. FieldStrategy updateStrategy() default FieldStrategy.DEFAULT;
  75. /**
  76. * 字段验证策略之 where: 表示该字段在拼接where条件时的策略
  77. * IGNORED: 直接拼接 column=#{columnProperty}
  78. * NOT_NULL: <if test="columnProperty != null">column=#{columnProperty}</if>
  79. * NOT_EMPTY: <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  80. *
  81. * @since 3.1.2
  82. */
  83. FieldStrategy whereStrategy() default FieldStrategy.DEFAULT;
  84. /**
  85. * 字段自动填充策略
  86. */
  87. FieldFill fill() default FieldFill.DEFAULT;
  88. /**
  89. * 是否进行 select 查询
  90. * <p>大字段可设置为 false 不加入 select 查询范围</p>
  91. */
  92. boolean select() default true;
  93. /**
  94. * 是否保持使用全局的 Format 的值
  95. * <p> 只生效于 既设置了全局的 Format 也设置了上面 {@link #value()} 的值 </p>
  96. * <li> 如果是 false , 全局的 Format 不生效 </li>
  97. *
  98. * @since 3.1.1
  99. */
  100. boolean keepGlobalFormat() default false;
  101. /**
  102. * JDBC类型 (该默认值不代表会按照该值生效)
  103. * <p>
  104. * {@link ResultMapping#jdbcType} and {@link ParameterMapping#jdbcType}
  105. *
  106. * @since 3.1.2
  107. */
  108. JdbcType jdbcType() default JdbcType.UNDEFINED;
  109. /**
  110. * 类型处理器 (该默认值不代表会按照该值生效)
  111. * <p>
  112. * {@link ResultMapping#typeHandler} and {@link ParameterMapping#typeHandler}
  113. *
  114. * @since 3.1.2
  115. */
  116. Class<? extends TypeHandler<?>> typeHandler() default UnknownTypeHandler.class;
  117. /**
  118. * 指定小数点后保留的位数
  119. * <p>
  120. * {@link ParameterMapping#numericScale}
  121. *
  122. * @since 3.1.2
  123. */
  124. String numericScale() default "";
  125. }