Java Code Examples for cn.hutool.core.util.StrUtil#removeSuffix()

The following examples show how to use cn.hutool.core.util.StrUtil#removeSuffix() . 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: HutoolController.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
@ApiOperation("StrUtil使用:字符串工具")
@GetMapping(value = "/strUtil")
public CommonResult strUtil() {
    //判断是否为空字符串
    String str = "test";
    StrUtil.isEmpty(str);
    StrUtil.isNotEmpty(str);
    //去除字符串的前后缀
    StrUtil.removeSuffix("a.jpg", ".jpg");
    StrUtil.removePrefix("a.jpg", "a.");
    //格式化字符串
    String template = "这只是个占位符:{}";
    String str2 = StrUtil.format(template, "我是占位符");
    LOGGER.info("/strUtil format:{}", str2);
    return CommonResult.success(null, "操作成功");
}
 
Example 2
Source File: ConstantFactory.java    From WebStack-Guns with MIT License 6 votes vote down vote up
/**
 * 通过角色ids获取角色名称
 */
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
    if (ToolUtil.isEmpty(roleIds)) {
        return "";
    }
    Integer[] roles = Convert.toIntArray(roleIds);
    StringBuilder sb = new StringBuilder();
    for (int role : roles) {
        Role roleObj = roleMapper.selectById(role);
        if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
            sb.append(roleObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}
 
Example 3
Source File: ConstantFactory.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
    if (ToolUtil.isEmpty(roleIds)) {
        return "";
    }
    Long[] roles = Convert.toLongArray(roleIds);
    StringBuilder sb = new StringBuilder();
    for (Long role : roles) {
        Role roleObj = roleMapper.selectById(role);
        if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
            sb.append(roleObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}
 
Example 4
Source File: ConstantFactory.java    From WebStack-Guns with MIT License 5 votes vote down vote up
/**
 * 获取菜单的名称们(多个)
 */
@Override
public String getMenuNames(String menuIds) {
    Integer[] menus = Convert.toIntArray(menuIds);
    StringBuilder sb = new StringBuilder();
    for (int menu : menus) {
        Menu menuObj = menuMapper.selectById(menu);
        if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
            sb.append(menuObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}
 
Example 5
Source File: ConstantFactory.java    From Guns with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getMenuNames(String menuIds) {
    Long[] menus = Convert.toLongArray(menuIds);
    StringBuilder sb = new StringBuilder();
    for (Long menu : menus) {
        Menu menuObj = menuMapper.selectById(menu);
        if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
            sb.append(menuObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}