Java Code Examples for com.ruoyi.common.utils.StringUtils#isEmpty()

The following examples show how to use com.ruoyi.common.utils.StringUtils#isEmpty() . 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: Convert.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 转换为Integer数组<br>
 * 
 * @param split 分隔符
 * @param split 被转换的值
 * @return 结果
 */
public static Integer[] toIntArray(String split, String str)
{
    if (StringUtils.isEmpty(str))
    {
        return new Integer[] {};
    }
    String[] arr = str.split(split);
    final Integer[] ints = new Integer[arr.length];
    for (int i = 0; i < arr.length; i++)
    {
        final Integer v = toInt(arr[i], 0);
        ints[i] = v;
    }
    return ints;
}
 
Example 2
Source File: PermissionService.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 验证用户是否具有以下任意一个角色
 *
 * @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
 * @return 用户是否具有以下任意一个角色
 */
public boolean hasAnyRoles(String roles)
{
    if (StringUtils.isEmpty(roles))
    {
        return false;
    }
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles()))
    {
        return false;
    }
    for (String role : roles.split(ROLE_DELIMETER))
    {
        if (hasRole(role))
        {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: Convert.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 转换为Number<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Number toNumber(Object value, Number defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Number)
    {
        return (Number) value;
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return NumberFormat.getInstance().parse(valueStr);
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 4
Source File: PageDomain.java    From ruoyiplus with MIT License 5 votes vote down vote up
public String getOrderBy()
{
    if (StringUtils.isEmpty(orderByColumn))
    {
        return "";
    }
    return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
}
 
Example 5
Source File: Convert.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 转换为BigDecimal<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof BigDecimal)
    {
        return (BigDecimal) value;
    }
    if (value instanceof Long)
    {
        return new BigDecimal((Long) value);
    }
    if (value instanceof Double)
    {
        return new BigDecimal((Double) value);
    }
    if (value instanceof Integer)
    {
        return new BigDecimal((Integer) value);
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return new BigDecimal(valueStr);
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 6
Source File: Convert.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 转换为double<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Double toDouble(Object value, Double defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Double)
    {
        return (Double) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).doubleValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        // 支持科学计数法
        return new BigDecimal(valueStr.trim()).doubleValue();
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 7
Source File: Convert.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 转换为int<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Integer toInt(Object value, Integer defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Integer)
    {
        return (Integer) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).intValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return Integer.parseInt(valueStr.trim());
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 8
Source File: Convert.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 转换为Short<br>
 * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Short toShort(Object value, Short defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Short)
    {
        return (Short) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).shortValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return Short.parseShort(valueStr.trim());
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 9
Source File: Convert.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 转换为Enum对象<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 
 * @param clazz Enum的Class
 * @param value 值
 * @param defaultValue 默认值
 * @return Enum
 */
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (clazz.isAssignableFrom(value.getClass()))
    {
        @SuppressWarnings("unchecked")
        E myE = (E) value;
        return myE;
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return Enum.valueOf(clazz, valueStr);
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 10
Source File: Convert.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 转换为Short<br>
 * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Short toShort(Object value, Short defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Short)
    {
        return (Short) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).shortValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return Short.parseShort(valueStr.trim());
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 11
Source File: Convert.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 转换为long<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Long toLong(Object value, Long defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Long)
    {
        return (Long) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).longValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        // 支持科学计数法
        return new BigDecimal(valueStr.trim()).longValue();
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 12
Source File: Convert.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 转换为long<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Long toLong(Object value, Long defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Long)
    {
        return (Long) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).longValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        // 支持科学计数法
        return new BigDecimal(valueStr.trim()).longValue();
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 13
Source File: Convert.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 转换为BigDecimal<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof BigDecimal)
    {
        return (BigDecimal) value;
    }
    if (value instanceof Long)
    {
        return new BigDecimal((Long) value);
    }
    if (value instanceof Double)
    {
        return new BigDecimal((Double) value);
    }
    if (value instanceof Integer)
    {
        return new BigDecimal((Integer) value);
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return new BigDecimal(valueStr);
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 14
Source File: Convert.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 转换为Float<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Float toFloat(Object value, Float defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Float)
    {
        return (Float) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).floatValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return Float.parseFloat(valueStr.trim());
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 15
Source File: Convert.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 转换为BigInteger<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static BigInteger toBigInteger(Object value, BigInteger defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof BigInteger)
    {
        return (BigInteger) value;
    }
    if (value instanceof Long)
    {
        return BigInteger.valueOf((Long) value);
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        return new BigInteger(valueStr);
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 16
Source File: BaseException.java    From supplierShop with MIT License 5 votes vote down vote up
@Override
public String getMessage()
{
    String message = null;
    if (!StringUtils.isEmpty(code))
    {
        message = MessageUtils.message(code, args);
    }
    if (message == null)
    {
        message = defaultMessage;
    }
    return message;
}
 
Example 17
Source File: CaptchaValidateFilter.java    From supplierShop with MIT License 5 votes vote down vote up
public boolean validateResponse(HttpServletRequest request, String validateCode)
{
    Object obj = ShiroUtils.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
    String code = String.valueOf(obj != null ? obj : "");
    if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(code))
    {
        return false;
    }
    return true;
}
 
Example 18
Source File: StoreGoodsController.java    From supplierShop with MIT License 4 votes vote down vote up
@PostMapping("/saveSpecAttr")
@ResponseBody
public AjaxResult saveSpecAttr(HttpServletRequest request){
    //获取所有表单参数
    Enumeration<String>  paramNames =  request.getParameterNames();
    Map<String,Map<String,String>> specDataMap = new HashMap<>();
    Map<String,String> attrDataMap = new HashMap<>();
    Map<String,String> tmpMap = null;
    String goodsId = request.getParameter("goodsId");
    String goodsType = request.getParameter("type_id");
    if(StringUtils.isEmpty(goodsId) || Integer.valueOf(goodsId) == 0){
        return AjaxResult.error("参数有误");
    }
    if(StringUtils.isEmpty(goodsType) || Integer.valueOf(goodsType) == 0){
        return AjaxResult.error("请选择模型");
    }
    //过滤参数
    while (paramNames.hasMoreElements()) {
        String  name = paramNames.nextElement();
        String[] values =  request.getParameterValues(name);
        if(values != null && values.length > 0){
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < values.length; i++) {
                builder.append(values[i]+" ");
            }
            //过滤规格组合新的规格数据集合
            if(name.contains("item")){
                String pattern = "item\\[(\\d+[_\\d+]*)]\\[([a-z]+_?[a-z]+)]";
                //String pattern = "item\\[(\\d+_\\d+)]\\[([a-z]+_?[a-z]+)]";
                Pattern r = Pattern.compile(pattern);
                Matcher m = r.matcher(name);
                if (m.find( )) {
                    String keyOne = m.group(1).trim();
                    System.out.println("keyOne:"+keyOne);
                    String keyTwo = m.group(2).trim();
                    System.out.println("keyTwo:"+keyTwo);
                    String keyValue = builder.toString().trim();

                    if(!specDataMap.containsKey(keyOne)){
                        tmpMap = new HashMap<>();
                    }
                    tmpMap.put(keyTwo,keyValue);
                    specDataMap.put(keyOne,tmpMap);

                }
            }

            //过滤属性组合新的属性集合
            if(name.contains("attr_")){
                String pattern2= "attr_(\\d+)\\[]";
                Pattern r2 = Pattern.compile(pattern2);
                Matcher m2 = r2.matcher(name);
                //System.out.println(name+" : "+builder.toString());
                if (m2.find( )) {
                    attrDataMap.put(m2.group(1),builder.toString().trim());
                }else{
                    System.out.println("no");
                }

            }
        }
    }




    if(specDataMap.isEmpty()){
        return AjaxResult.error("请选择规格项目");
    }

    if(attrDataMap.isEmpty()){
        return AjaxResult.error("请填写商品属性");
    }

    storeGoodsService.saveSpecAttr(specDataMap,attrDataMap,goodsId,goodsType);

    return AjaxResult.success("操作成功");
}
 
Example 19
Source File: JobInvokeUtil.java    From RuoYi-Vue with MIT License 4 votes vote down vote up
/**
 * 获取method方法参数相关列表
 * 
 * @param invokeTarget 目标字符串
 * @return method方法相关参数列表
 */
public static List<Object[]> getMethodParams(String invokeTarget)
{
    String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
    if (StringUtils.isEmpty(methodStr))
    {
        return null;
    }
    String[] methodParams = methodStr.split(",");
    List<Object[]> classs = new LinkedList<>();
    for (int i = 0; i < methodParams.length; i++)
    {
        String str = StringUtils.trimToEmpty(methodParams[i]);
        // String字符串类型,包含'
        if (StringUtils.contains(str, "'"))
        {
            classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class });
        }
        // boolean布尔类型,等于true或者false
        else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false"))
        {
            classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
        }
        // long长整形,包含L
        else if (StringUtils.containsIgnoreCase(str, "L"))
        {
            classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class });
        }
        // double浮点类型,包含D
        else if (StringUtils.containsIgnoreCase(str, "D"))
        {
            classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class });
        }
        // 其他类型归类为整形
        else
        {
            classs.add(new Object[] { Integer.valueOf(str), Integer.class });
        }
    }
    return classs;
}
 
Example 20
Source File: EscapeUtil.java    From RuoYi-Vue with MIT License 4 votes vote down vote up
/**
 * Escape解码
 * 
 * @param content 被转义的内容
 * @return 解码后的字符串
 */
public static String decode(String content)
{
    if (StringUtils.isEmpty(content))
    {
        return content;
    }

    StringBuilder tmp = new StringBuilder(content.length());
    int lastPos = 0, pos = 0;
    char ch;
    while (lastPos < content.length())
    {
        pos = content.indexOf("%", lastPos);
        if (pos == lastPos)
        {
            if (content.charAt(pos + 1) == 'u')
            {
                ch = (char) Integer.parseInt(content.substring(pos + 2, pos + 6), 16);
                tmp.append(ch);
                lastPos = pos + 6;
            }
            else
            {
                ch = (char) Integer.parseInt(content.substring(pos + 1, pos + 3), 16);
                tmp.append(ch);
                lastPos = pos + 3;
            }
        }
        else
        {
            if (pos == -1)
            {
                tmp.append(content.substring(lastPos));
                lastPos = content.length();
            }
            else
            {
                tmp.append(content.substring(lastPos, pos));
                lastPos = pos;
            }
        }
    }
    return tmp.toString();
}