com.baomidou.mybatisplus.toolkit.StringUtils Java Examples

The following examples show how to use com.baomidou.mybatisplus.toolkit.StringUtils. 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;
}
 
Example #3
Source File: MyBeanWrapperFieldSetMapper.java    From SpringBootBucket with MIT License 6 votes vote down vote up
@Override
protected void initBinder(DataBinder binder) {
    binder.registerCustomEditor(Timestamp.class, new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            if (StringUtils.isNotEmpty(text)) {
                setValue(DateUtil.parseTimestamp(text));
            } else {
                setValue(null);
            }
        }

        @Override
        public String getAsText() throws IllegalArgumentException {
            Object date = getValue();
            if (date != null) {
                return DateUtil.formatTimestamp((Timestamp) date);
            } else {
                return "";
            }
        }
    });
}
 
Example #4
Source File: GlobalConfig.java    From mybatis-plus-sharding-jdbc-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
public GlobalConfiguration convertGlobalConfiguration() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    GlobalConfiguration globalConfiguration = new GlobalConfiguration();
    if (StringUtils.isNotEmpty(this.getIdentifierQuote())) {
        globalConfiguration.setIdentifierQuote(this.getIdentifierQuote());
    }
    if (StringUtils.isNotEmpty(this.getLogicDeleteValue())) {
        globalConfiguration.setLogicDeleteValue(this.getLogicDeleteValue());
    }
    if (StringUtils.isNotEmpty(this.getLogicNotDeleteValue())) {
        globalConfiguration.setLogicNotDeleteValue(this.getLogicNotDeleteValue());
    }
    if (StringUtils.isNotEmpty(this.getSqlInjector())) {
        globalConfiguration.setSqlInjector((ISqlInjector) Class.forName(this.getSqlInjector()).newInstance());
    }
    if (StringUtils.isNotEmpty(this.getMetaObjectHandler())) {
        globalConfiguration.setMetaObjectHandler((MetaObjectHandler) Class.forName(this.getMetaObjectHandler()).newInstance());
    }
    if (StringUtils.isNotEmpty(this.getKeyGenerator())) {
        globalConfiguration.setKeyGenerator((IKeyGenerator) Class.forName(this.getKeyGenerator()).newInstance());
    }
    if (StringUtils.checkValNotNull(this.getIdType())) {
        globalConfiguration.setIdType(this.getIdType());
    }
    if (null != this.getDbColumnUnderline()) {
        globalConfiguration.setDbColumnUnderline(this.getDbColumnUnderline());
    }
    if (StringUtils.checkValNotNull(this.getFieldStrategy())) {
        globalConfiguration.setFieldStrategy(this.getFieldStrategy());
    }
    if (StringUtils.checkValNotNull(this.getRefreshMapper())) {
        globalConfiguration.setRefresh(this.getRefreshMapper());
    }
    if (StringUtils.checkValNotNull(this.getCapitalMode())) {
        globalConfiguration.setCapitalMode(this.getCapitalMode());
    }
    if (null != this.getSqlParserCache()) {
        globalConfiguration.setSqlParserCache(this.getSqlParserCache());
    }
    return globalConfiguration;
}
 
Example #5
Source File: PigResourcesGenerator.java    From pig with MIT License 5 votes vote down vote up
/**
 * 页面生成的文件名
 */
private static String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
    String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
    String path = viewOutputDir + "/" + name + "/index"  + suffixPath;
    File viewDir = new File(path).getParentFile();
    if (!viewDir.exists()) {
        viewDir.mkdirs();
    }
    return path;
}
 
Example #6
Source File: MysqlGenerator.java    From xmanager with Apache License 2.0 5 votes vote down vote up
/**
 * 页面生成的文件名
 */
private static String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
	String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
	String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
	File viewDir = new File(path).getParentFile();
	if (!viewDir.exists()) {
		viewDir.mkdirs();
	}
	return path;
}
 
Example #7
Source File: AdminTypeController.java    From MI-S with MIT License 5 votes vote down vote up
/**
 * 加载分类信息列表
 * @param pages 分页对象
 * @param param  搜索条件
 * @param model
 * @return
 */
@RequestMapping("/list")
public String selectPage(Page pages, String param, Model model) {
    Page<Type> page;
    EntityWrapper<Type> ex = new EntityWrapper<>();
    if (StringUtils.checkValNotNull(param)) {
        ex.where("type_name like concat('%',{0},'%')", param);
    }
    ex.orderBy("sort", true);
    ex.orderBy("create_time", true);
    page = iTypeService.selectPage(new Page(pages.getCurrent(), pages.getSize()), ex);
    model.addAttribute("page", page);
    return "admin/type/typeTable";
}
 
Example #8
Source File: AdminFlinkController.java    From MI-S with MIT License 5 votes vote down vote up
/**
 * 加载列表(分页)
 * @return
 */
@RequestMapping("/list")
public String selectPage(Page pages, String param, Model model) {
    Page<Friendlink> page;
    EntityWrapper<Friendlink> ex = new EntityWrapper<>();
    if (StringUtils.checkValNotNull(param)) {
        ex.where("site_name like concat('%',{0},'%')", param);
    }
    page = iFriendlinkService.selectPage(new Page(pages.getCurrent(), pages.getSize()), ex);
    model.addAttribute("page", page);
    return "admin/flink/flinkTable";
}
 
Example #9
Source File: AdminTagController.java    From MI-S with MIT License 5 votes vote down vote up
/**
 * 分页加载标签
 * @param pages 分页对象
 * @param param  搜索条件
 * @param model
 * @return
 */
@RequestMapping("/list")
public String selectPage(Page pages, String param, Model model) {
    Page<Tag> page;
    EntityWrapper<Tag> ex = new EntityWrapper<>();
    if (StringUtils.checkValNotNull(param)) {
        ex.where("tag_name like concat('%',{0},'%')", param);
    }
    ex.orderBy("sort", true);
    ex.orderBy("create_time", true);
    page = iTagService.selectPage(new Page(pages.getCurrent(), pages.getSize()), ex);
    model.addAttribute("page", page);
    return "admin/tag/tagTable";
}