0
点赞
收藏
分享

微信扫一扫

通用工具类

/**
 * @author BNTang
 */
public class CommonsUtils {

    /**
     * 获取uuid
     *
     * @return uuid字符串
     */
    public static String getUUID() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replaceAll("-", "");
        
        return uuid;
    }

    /**
     * 随机生成,获取编号
     *
     * @return 生成的编号
     */
    public static String getOrderNo(int randomCount) {
        String strDate = DateUtils.formatDate(new Date(), DateUtils.YMDHMS);
        StringBuffer orderNoBuffer = new StringBuffer();
        // 时间 + randomCount * 2 位随机数
        orderNoBuffer.append(strDate);
        for (int i = 0; i < 2; i++) {
            orderNoBuffer.append(RandomStringUtils.randomNumeric(randomCount));
        }
        
        return orderNoBuffer.toString();
    }

    /**
     * 数字转化
     *
     * @param bigDecimal 需要装换的数字
     * @return 转换之后的数字
     */
    public static BigDecimal stringToBigDecimal(String bigDecimal) {
        String strNum = StringUtils.isBlank(bigDecimal) ? "0" : bigDecimal;
        
        return new BigDecimal(strNum);
    }

    /**
     * 实现首字母大写
     *
     * @param str 字符串
     * @return 首字符大写的字符串
     */
    public static String upperCase(String str) {
        char[] ch = str.toCharArray();
        if (ch[0] >= 'a' && ch[0] <= 'z') {
            ch[0] = (char) (ch[0] - 32);
        }
        
        return new String(ch);
    }
}


举报

相关推荐

0 条评论