TableField.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * 当该Field为类对象时, 可使用#{对象.属性}来映射到数据表.
  39. * <p>支持:@TableField(el = "role, jdbcType=BIGINT) 推荐使用{@link TableField#jdbcType()} </p>
  40. * <p>支持:@TableField(el = "role, typeHandler=com.baomidou.springcloud.typehandler.PhoneTypeHandler") 推荐使用{@link TableField#typeHandler()} </p>
  41. */
  42. @Deprecated
  43. String el() default "";
  44. /**
  45. * 是否为数据库表字段
  46. * <p>默认 true 存在,false 不存在</p>
  47. */
  48. boolean exist() default true;
  49. /**
  50. * 字段 where 实体查询比较条件
  51. * <p>默认 `=` 等值</p>
  52. */
  53. String condition() default "";
  54. /**
  55. * 字段 update set 部分注入, 该注解优于 el 注解使用
  56. * <p>例如:@TableField(.. , update="%s+1") 其中 %s 会填充为字段</p>
  57. * <p>输出 SQL 为:update 表 set 字段=字段+1 where ...</p>
  58. * <p>例如:@TableField(.. , update="now()") 使用数据库时间</p>
  59. * <p>输出 SQL 为:update 表 set 字段=now() where ...</p>
  60. */
  61. String update() default "";
  62. /**
  63. * 字段验证策略
  64. * <p>默认追随全局配置</p>
  65. *
  66. * @since deprecated v_3.1.2 @2019-5-7
  67. * @deprecated v_3.1.2 please use {@link #insertStrategy} and {@link #updateStrategy} and {@link #whereStrategy}
  68. */
  69. @Deprecated
  70. FieldStrategy strategy() default FieldStrategy.DEFAULT;
  71. /**
  72. * 字段验证策略之 insert: 当insert操作时,该字段拼接insert语句时的策略
  73. * IGNORED: 直接拼接 insert into table_a(column) values (#{columnProperty});
  74. * NOT_NULL: insert into table_a(<if test="columnProperty != null">column</if>) values (<if test="columnProperty != null">#{columnProperty}</if>)
  75. * NOT_EMPTY: insert into table_a(<if test="columnProperty != null and columnProperty!=''">column</if>) values (<if test="columnProperty != null and columnProperty!=''">#{columnProperty}</if>)
  76. *
  77. * @since added v_3.1.2 @2019-5-7
  78. */
  79. FieldStrategy insertStrategy() default FieldStrategy.DEFAULT;
  80. /**
  81. * 字段验证策略之 update: 当更新操作时,该字段拼接set语句时的策略
  82. * IGNORED: 直接拼接 update table_a set column=#{columnProperty}, 属性为null/空string都会被set进去
  83. * NOT_NULL: update table_a set <if test="columnProperty != null">column=#{columnProperty}</if>
  84. * NOT_EMPTY: update table_a set <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  85. *
  86. * @since added v_3.1.2 @2019-5-7
  87. */
  88. FieldStrategy updateStrategy() default FieldStrategy.DEFAULT;
  89. /**
  90. * 字段验证策略之 where: 表示该字段在拼接where条件时的策略
  91. * IGNORED: 直接拼接 column=#{columnProperty}
  92. * NOT_NULL: <if test="columnProperty != null">column=#{columnProperty}</if>
  93. * NOT_EMPTY: <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  94. *
  95. * @since added v_3.1.2 @2019-5-7
  96. */
  97. FieldStrategy whereStrategy() default FieldStrategy.DEFAULT;
  98. /**
  99. * 字段自动填充策略
  100. */
  101. FieldFill fill() default FieldFill.DEFAULT;
  102. /**
  103. * 是否进行 select 查询
  104. * <p>大字段可设置为 false 不加入 select 查询范围</p>
  105. */
  106. boolean select() default true;
  107. /**
  108. * 是否保持使用全局的 Format 的值
  109. * <p> 只生效于 既设置了全局的 Format 也设置了上面 {@link #value()} 的值 </p>
  110. * <li> 如果是 false , 全局的 Format 不生效 </li>
  111. *
  112. * @since 3.1.1
  113. */
  114. boolean keepGlobalFormat() default false;
  115. /**
  116. * JDBC类型(该默认值不代表会按照该值生效)
  117. *
  118. * <li> {@link ResultMapping#jdbcType} </li>
  119. * <li> {@link ParameterMapping#jdbcType} </li>
  120. *
  121. * @return JDBC类型
  122. * @since 3.1.2
  123. */
  124. JdbcType jdbcType() default JdbcType.UNDEFINED;
  125. /**
  126. * 类型处理器(该默认值不代表会按照该值生效)
  127. *
  128. * <li> {@link ResultMapping#typeHandler} </li>
  129. * <li> {@link ParameterMapping#typeHandler} </li>
  130. *
  131. * @return 类型处理器
  132. * @since 3.1.2
  133. */
  134. Class<? extends TypeHandler<?>> typeHandler() default UnknownTypeHandler.class;
  135. }