TableField.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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, ElementType.TYPE})
  32. public @interface TableField {
  33. /**
  34. * 数据库字段值,
  35. * 不需要配置该值的情况:
  36. * <li> 当 {@link com.baomidou.mybatisplus.core.MybatisConfiguration#mapUnderscoreToCamelCase} 为 true 时,
  37. * (mp下默认是true,mybatis默认是false), 数据库字段值.replace("_","").toUpperCase() == 实体属性名.toUpperCase() </li>
  38. * <li> 当 {@link com.baomidou.mybatisplus.core.MybatisConfiguration#mapUnderscoreToCamelCase} 为 false 时,
  39. * 数据库字段值.toUpperCase() == 实体属性名.toUpperCase()</li>
  40. */
  41. String value() default "";
  42. /**
  43. * 是否为数据库表字段
  44. * 默认 true 存在,false 不存在
  45. */
  46. boolean exist() default true;
  47. /**
  48. * 字段 where 实体查询比较条件
  49. * 默认 `=` 等值
  50. */
  51. String condition() default "";
  52. /**
  53. * 字段 update set 部分注入, 该注解优于 el 注解使用
  54. * <p>
  55. * 例1:@TableField(.. , update="%s+1") 其中 %s 会填充为字段
  56. * 输出 SQL 为:update 表 set 字段=字段+1 where ...
  57. * <p>
  58. * 例2:@TableField(.. , update="now()") 使用数据库时间
  59. * 输出 SQL 为:update 表 set 字段=now() where ...
  60. */
  61. String update() default "";
  62. /**
  63. * 字段验证策略之 insert: 当insert操作时,该字段拼接insert语句时的策略
  64. * IGNORED: 直接拼接 insert into table_a(column) values (#{columnProperty});
  65. * NOT_NULL: insert into table_a(<if test="columnProperty != null">column</if>) values (<if test="columnProperty != null">#{columnProperty}</if>)
  66. * NOT_EMPTY: insert into table_a(<if test="columnProperty != null and columnProperty!=''">column</if>) values (<if test="columnProperty != null and columnProperty!=''">#{columnProperty}</if>)
  67. *
  68. * @since 3.1.2
  69. */
  70. FieldStrategy insertStrategy() default FieldStrategy.DEFAULT;
  71. /**
  72. * 字段验证策略之 update: 当更新操作时,该字段拼接set语句时的策略
  73. * IGNORED: 直接拼接 update table_a set column=#{columnProperty}, 属性为null/空string都会被set进去
  74. * NOT_NULL: update table_a set <if test="columnProperty != null">column=#{columnProperty}</if>
  75. * NOT_EMPTY: update table_a set <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  76. *
  77. * @since 3.1.2
  78. */
  79. FieldStrategy updateStrategy() default FieldStrategy.DEFAULT;
  80. /**
  81. * 字段验证策略之 where: 表示该字段在拼接where条件时的策略
  82. * IGNORED: 直接拼接 column=#{columnProperty}
  83. * NOT_NULL: <if test="columnProperty != null">column=#{columnProperty}</if>
  84. * NOT_EMPTY: <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
  85. *
  86. * @since 3.1.2
  87. */
  88. FieldStrategy whereStrategy() default FieldStrategy.DEFAULT;
  89. /**
  90. * 字段自动填充策略
  91. */
  92. FieldFill fill() default FieldFill.DEFAULT;
  93. /**
  94. * 是否进行 select 查询
  95. * <p>大字段可设置为 false 不加入 select 查询范围</p>
  96. */
  97. boolean select() default true;
  98. /**
  99. * 是否保持使用全局的 Format 的值
  100. * <p> 只生效于 既设置了全局的 Format 也设置了上面 {@link #value()} 的值 </p>
  101. * <li> 如果是 false , 全局的 Format 不生效 </li>
  102. *
  103. * @since 3.1.1
  104. */
  105. boolean keepGlobalFormat() default false;
  106. /**
  107. * JDBC类型 (该默认值不代表会按照该值生效),
  108. * 只生效与 mp 自动注入的 method,
  109. * 建议配合 {@link TableName#autoResultMap()} 一起使用
  110. * <p>
  111. * {@link ResultMapping#jdbcType} and {@link ParameterMapping#jdbcType}
  112. *
  113. * @since 3.1.2
  114. */
  115. JdbcType jdbcType() default JdbcType.UNDEFINED;
  116. /**
  117. * 类型处理器 (该默认值不代表会按照该值生效),
  118. * 只生效与 mp 自动注入的 method,
  119. * 建议配合 {@link TableName#autoResultMap()} 一起使用
  120. * <p>
  121. * {@link ResultMapping#typeHandler} and {@link ParameterMapping#typeHandler}
  122. *
  123. * @since 3.1.2
  124. */
  125. Class<? extends TypeHandler> typeHandler() default UnknownTypeHandler.class;
  126. /**
  127. * 指定小数点后保留的位数,
  128. * 只生效与 mp 自动注入的 method,
  129. * 建议配合 {@link TableName#autoResultMap()} 一起使用
  130. * <p>
  131. * {@link ParameterMapping#numericScale}
  132. *
  133. * @since 3.1.2
  134. */
  135. String numericScale() default "";
  136. }