本文整理汇总了Java中com.baomidou.mybatisplus.annotations.TableField.exist方法的典型用法代码示例。如果您正苦于以下问题:Java TableField.exist方法的具体用法?Java TableField.exist怎么用?Java TableField.exist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.baomidou.mybatisplus.annotations.TableField
的用法示例。
在下文中一共展示了TableField.exist方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
}