001/* 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.annotation; 017 018import org.apache.ibatis.type.JdbcType; 019import org.apache.ibatis.type.TypeHandler; 020import org.apache.ibatis.type.UnknownTypeHandler; 021 022import java.lang.annotation.*; 023 024/** 025 * 数据库表中的列信息注解。 026 * 027 * @author 开源海哥 028 */ 029@Inherited 030@Retention(RetentionPolicy.RUNTIME) 031@Target({ElementType.FIELD}) 032public @interface Column { 033 034 /** 035 * 字段名称。 036 */ 037 String value() default ""; 038 039 /** 040 * 是否忽略该字段,可能只是业务字段,而非数据库对应字段。 041 */ 042 boolean ignore() default false; 043 044 /** 045 * insert 的时候默认值,这个值会直接被拼接到 sql 而不通过参数设置。 046 */ 047 String onInsertValue() default ""; 048 049 /** 050 * update 的时候自动赋值,这个值会直接被拼接到 sql 而不通过参数设置。 051 */ 052 String onUpdateValue() default ""; 053 054 /** 055 * 是否是大字段,大字段 APT 不会生成到 DEFAULT_COLUMNS 里。 056 */ 057 boolean isLarge() default false; 058 059 /** 060 * <p>是否是逻辑删除字段,一张表中只能存在 1 一个逻辑删除字段。 061 * 062 * <p>逻辑删除的字段,被删除时,会设置为 1,正常状态为 0,可以通过 FlexGlobalConfig 配置来修改 1 和 0 为其他值。 063 */ 064 boolean isLogicDelete() default false; 065 066 /** 067 * <p>是否为乐观锁字段。 068 * 069 * <p>若是乐观锁字段的话,数据更新的时候会去检测当前版本号,若更新成功的话会设置当前版本号 +1 070 * 只能用于数值的字段。 071 */ 072 boolean version() default false; 073 074 /** 075 * 是否是租户 ID。 076 */ 077 boolean tenantId() default false; 078 079 /** 080 * 配置的 jdbcType。 081 */ 082 JdbcType jdbcType() default JdbcType.UNDEFINED; 083 084 /** 085 * 自定义 TypeHandler。 086 */ 087 Class<? extends TypeHandler> typeHandler() default UnknownTypeHandler.class; 088 089}