Java Code Examples for com.baomidou.mybatisplus.toolkit.StringUtils#checkValNull()

The following examples show how to use com.baomidou.mybatisplus.toolkit.StringUtils#checkValNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseServiceImpl.java    From cola-cloud with MIT License 6 votes vote down vote up
/**
 * <p>
 * TableId 注解存在更新记录,否插入一条记录
 * </p>
 *
 * @param entity 实体对象
 * @return boolean
 */
@Transactional(rollbackFor = Exception.class)
@Override
public boolean insertOrUpdate(T entity) {
    if (null != entity) {
        Class<?> cls = entity.getClass();
        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
        if (null != tableInfo && StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
            Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty());
            if (StringUtils.checkValNull(idVal)) {
                return insert(entity);
            } else {
                /*
                 * 更新成功直接返回,失败执行插入逻辑
                 */
                return updateById(entity) || insert(entity);
            }
        } else {
            throw new MybatisPlusException("Error:  Can not execute. Could not find @TableId.");
        }
    }
    return false;
}
 
Example 2
Source File: BaseServiceImpl.java    From cola-cloud with MIT License 6 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
@Override
public boolean insertOrUpdateAllColumn(T entity) {
    if (null != entity) {
        Class<?> cls = entity.getClass();
        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
        if (null != tableInfo && StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
            Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty());
            if (StringUtils.checkValNull(idVal)) {
                return insertAllColumn(entity);
            } else {
                /*
                 * 更新成功直接返回,失败执行插入逻辑
                 */
                return updateAllColumnById(entity) || insertAllColumn(entity);
            }
        } else {
            throw new MybatisPlusException("Error:  Can not execute. Could not find @TableId.");
        }
    }
    return false;
}