Java Code Examples for cn.hutool.core.convert.Convert#toIntArray()

The following examples show how to use cn.hutool.core.convert.Convert#toIntArray() . 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("Convert使用:类型转换工具类")
@GetMapping(value = "/covert")
public CommonResult covert() {
    //转换为字符串
    int a = 1;
    String aStr = Convert.toStr(a);
    //转换为指定类型数组
    String[] b = {"1", "2", "3", "4"};
    Integer[] bArr = Convert.toIntArray(b);
    //转换为日期对象
    String dateStr = "2017-05-06";
    Date date = Convert.toDate(dateStr);
    //转换为列表
    String[] strArr = {"a", "b", "c", "d"};
    List<String> strList = Convert.toList(String.class, strArr);
    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 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 4
Source File: DemoOperateController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 删除用户
 */
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
    Integer[] userIds = Convert.toIntArray(ids);
    for (Integer userId : userIds) {
        USERS.remove(userId);
    }
    return AjaxResult.success();
}