本文整理汇总了Java中com.baomidou.mybatisplus.annotations.TableField类的典型用法代码示例。如果您正苦于以下问题:Java TableField类的具体用法?Java TableField怎么用?Java TableField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TableField类属于com.baomidou.mybatisplus.annotations包,在下文中一共展示了TableField类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllFields
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* 获取该类的所有属性列表
*
* @param clazz 反射类
* @return
*/
public static List<Field> getAllFields(Class<?> clazz) {
List<Field> fieldList = ReflectionKit.getFieldList(clazz);
if (CollectionUtils.isNotEmpty(fieldList)) {
Iterator<Field> iterator = fieldList.iterator();
while (iterator.hasNext()) {
Field field = iterator.next();
/* 过滤注解非表字段属性 */
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && !tableField.exist()) {
iterator.remove();
}
}
}
return fieldList;
}
示例2: insert
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
public String insert(CommonSaveParam param) {
StringBuilder sb = new StringBuilder("insert into ");
sb.append(param.getTableName());
sb.append(" (");
Field[] fields = param.gettClass().getDeclaredFields();
StringBuilder valueBuilder = new StringBuilder();
for (Field field : fields) {
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && !tableField.exist()) continue;
String fieldName = tableField == null ? field.getName() : tableField.value();
if (fieldName == "id" || fieldName == "createTime" || fieldName == "modifiedTime") continue;
String fieldValue = getFieldValue(param.getEntityDTO(), field);
if (fieldValue == "" || fieldValue == "''") continue;
sb.append("`");
sb.append(fieldName);
sb.append("`,");
valueBuilder.append(fieldValue + ",");
}
String createTime = "'" + dateFormat.format(new Date()) + "'";
sb.append("createTime) values (" + valueBuilder.toString() + createTime + ")");
return sb.toString();
}
示例3: update
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
public String update(CommonSaveParam param) {
Long id = param.getEntityDTO().getId();
if (id == null || id <= 0) return "";
StringBuilder sb = new StringBuilder("update ");
sb.append(param.getTableName());
sb.append(" set ");
Field[] fields = param.gettClass().getDeclaredFields();
for (Field field : fields) {
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && !tableField.exist()) continue;
String fieldName = tableField == null ? field.getName() : tableField.value();
if (fieldName == "id" || fieldName == "createTime" || fieldName == "modifiedTime") continue;
String fieldValue = getFieldValue(param.getEntityDTO(), field);
sb.append("`" + fieldName + "` = " + fieldValue);
sb.append(",");
}
String modifiedTime = "'" + dateFormat.format(new Date()) + "'";
sb.append("modifiedTime = " + modifiedTime);
sb.append(" where id = " + id);
return sb.toString();
}
示例4: getAllFields
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* 获取该类的所有属性列表
*
* @param clazz 反射类
* @return
*/
public static List<Field> getAllFields(Class<?> clazz) {
List<Field> fieldList = ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz));
if (CollectionUtils.isNotEmpty(fieldList)) {
Iterator<Field> iterator = fieldList.iterator();
while (iterator.hasNext()) {
Field field = iterator.next();
/* 过滤注解非表字段属性 */
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && !tableField.exist()) {
iterator.remove();
}
}
}
return fieldList;
}
示例5: TableFieldInfo
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* <p>
* 存在 TableField 注解构造函数
* </p>
*/
public TableFieldInfo(GlobalConfiguration globalConfig, String column,
String el, Field field, TableField tableField) {
this.property = field.getName();
this.propertyType = field.getType().getName();
/*
* 1、注解 value 不存在,开启字段下划线申明<br>
* 2、没有开启下划线申明,但是column与property不等的情况<br>
* 设置 related 为 true
*/
if (StringUtils.isEmpty(tableField.value())
&& globalConfig.isDbColumnUnderline()) {
/* 开启字段下划线申明 */
this.related = true;
this.setColumn(globalConfig, StringUtils.camelToUnderline(column));
} else {
this.setColumn(globalConfig, column);
if (!column.equals(this.property)) {
this.related = true;
}
}
this.el = el;
/*
* 优先使用单个字段注解,否则使用全局配置<br>
* 自定义字段验证策略 fixed-239
*/
if (FieldStrategy.NOT_NULL != tableField.validate()) {
this.fieldStrategy = tableField.validate();
} else {
this.fieldStrategy = globalConfig.getFieldStrategy();
}
/*
* 保存当前字段的插入忽略,更新忽略值
*/
this.insertIgnore = tableField.insertIgnore();
this.updateIgnore = tableField.updateIgnore();
}
示例6: initTableField
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* <p>
* 字段属性初始化
* </p>
*
* @param globalConfig 全局配置
* @param tableInfo 表信息
* @param fieldList 字段列表
* @param clazz 当前表对象类
* @return true 继续下一个属性判断,返回 continue;
*/
private static boolean initTableField(GlobalConfiguration globalConfig, TableInfo tableInfo, List<TableFieldInfo> fieldList,
Field field, Class<?> clazz) {
/* 获取注解属性,自定义字段 */
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null) {
String columnName = field.getName();
if (StringUtils.isNotEmpty(tableField.value())) {
columnName = tableField.value();
}
/*
* el 语法支持,可以传入多个参数以逗号分开
*/
String el = field.getName();
if (StringUtils.isNotEmpty(tableField.el())) {
el = tableField.el();
}
String[] columns = columnName.split(";");
String[] els = el.split(";");
if (columns.length == els.length) {
for (int i = 0; i < columns.length; i++) {
fieldList.add(new TableFieldInfo(globalConfig, columns[i], els[i], field, tableField));
}
} else {
String errorMsg = "Class: %s, Field: %s, 'value' 'el' Length must be consistent.";
throw new MybatisPlusException(String.format(errorMsg, clazz.getName(), field.getName()));
}
return true;
}
return false;
}
示例7: TableFieldInfo
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* <p>
* 存在 TableField 注解构造函数
* </p>
*/
public TableFieldInfo(GlobalConfiguration globalConfig, TableInfo tableInfo, String column,
String el, Field field, TableField tableField) {
this.property = field.getName();
this.propertyType = field.getType();
/*
* 1、注解 value 不存在,开启字段下划线申明<br>
* 2、没有开启下划线申明,但是column与property不等的情况<br>
* 设置 related 为 true
*/
if (StringUtils.isEmpty(tableField.value())
&& globalConfig.isDbColumnUnderline()) {
/* 开启字段下划线申明 */
this.related = true;
this.setColumn(globalConfig, StringUtils.camelToUnderline(column));
} else {
this.setColumn(globalConfig, column);
if (!column.equals(this.property)) {
this.related = true;
}
}
this.el = el;
/*
* 优先使用单个字段注解,否则使用全局配置<br>
* 自定义字段验证策略 fixed-239
*/
if (FieldStrategy.NOT_NULL != tableField.strategy()) {
this.fieldStrategy = tableField.strategy();
} else {
this.fieldStrategy = globalConfig.getFieldStrategy();
}
tableInfo.setLogicDelete(this.initLogicDelete(globalConfig, field));
this.update = tableField.update();
this.condition = tableField.condition();
/*
* 保存当前字段的填充策略
*/
this.fieldFill = tableField.fill();
}
示例8: initTableField
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* <p>
* 字段属性初始化
* </p>
*
* @param globalConfig 全局配置
* @param tableInfo 表信息
* @param fieldList 字段列表
* @param clazz 当前表对象类
* @return true 继续下一个属性判断,返回 continue;
*/
private static boolean initTableField(GlobalConfiguration globalConfig, TableInfo tableInfo, List<TableFieldInfo> fieldList,
Field field, Class<?> clazz) {
/* 获取注解属性,自定义字段 */
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null) {
String columnName = field.getName();
if (StringUtils.isNotEmpty(tableField.value())) {
columnName = tableField.value();
}
/*
* el 语法支持,可以传入多个参数以逗号分开
*/
String el = field.getName();
if (StringUtils.isNotEmpty(tableField.el())) {
el = tableField.el();
}
String[] columns = columnName.split(";");
String[] els = el.split(";");
if (columns.length == els.length) {
for (int i = 0; i < columns.length; i++) {
fieldList.add(new TableFieldInfo(globalConfig, tableInfo, columns[i], els[i], field, tableField));
}
} else {
String errorMsg = "Class: %s, Field: %s, 'value' 'el' Length must be consistent.";
throw new MybatisPlusException(String.format(errorMsg, clazz.getName(), field.getName()));
}
return true;
}
return false;
}
示例9: initWithClass
import com.baomidou.mybatisplus.annotations.TableField; //导入依赖的package包/类
/**
* 根据Class名称初始化select与from
* 如果select不为空,selectSql = select + tClass反射得到的select
*/
private void initWithClass() {
if (this.tClass == null) return;
if (StringUtils.isBlank(this.select)) {
StringBuilder sb = new StringBuilder();
List<Field> fields = new ArrayList<>();
Class tempClass = tClass;
while (tempClass != null && !tempClass.getName().toLowerCase().equals("java.lang.object")) {
Field[] tempFields = tempClass.getDeclaredFields();
fields.addAll(Arrays.asList(tempFields));
tempClass = tempClass.getSuperclass();
}
for (Field field : fields) {
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && !tableField.exist()) continue;
String fieldName = field.getName();
String dbFieldName = tableField == null ? fieldName : tableField.value();
if (!StringUtils.startsWith(dbFieldName, "`")) {
sb.append("`");
}
sb.append(dbFieldName);
if (!StringUtils.endsWith(dbFieldName, "`")) {
sb.append("`");
}
if (!fieldName.equals(dbFieldName)) {
sb.append(" AS ");
sb.append(fieldName);
}
sb.append(",");
}
this.select = StringHelper.trimEnd(sb.toString(), ',');
}
//如果from为空,则使用tClass的TableName
if (StringUtils.isBlank(this.from)) {
TableName tableName = this.tClass.getAnnotation(TableName.class);
if (tableName != null) {
this.from = tableName.value();
}
}
}