fengxiang
2017-12-27 d07553f8cfdc4ce407122f905b49191b8ffbc7fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.moral.common.util;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class StringUtils {
    public static final char UNDERLINE = '_';
 
    /**
     * 驼峰格式字符串转换为下划线格式字符串
     * 
     * @param param
     * @return
     */
    public static String camelToUnderline(String param) {
        if (param == null || "".equals(param.trim())) {
            return "";
        }
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = param.charAt(i);
            if (Character.isUpperCase(c)) {
                sb.append(UNDERLINE);
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
 
    
    /**
     * //首字母转大写
     * 
     * @param s
     * @return
     */
    public static String toUpperCaseFirstOne(String s){
        StringBuilder sb = new StringBuilder(s);
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        return sb.toString();
    }
    public static boolean isNullOrEmpty(String toTest) {
        return toTest == null || toTest.length() == 0;
    }
    public static Object stringToObject4Type(Class<?> type,String value) throws Exception{
        Object result = value;
        if (type == double.class || type == Double.class) {
            result = Double.parseDouble(value);
        } else if (type == float.class || type == Float.class) {
            result = Float.parseFloat(value);
        } else if (type == long.class || type == Long.class) {
            result = Long.parseLong(value);
        } else if (type == int.class || type == Integer.class) {
            result = Integer.parseInt(value);
        } else if (type == short.class || type == Short.class) {
            result = Short.parseShort(value);
        } else if (type == boolean.class || type == Boolean.class) {
            result = Boolean.parseBoolean(value);
        } else if (type == Date.class) {
            value = value.replace("T", " ");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                result = df.parse(value);
            } catch (Exception e) {
                df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                try {
                    result = df.parse(value);
                } catch (ParseException e1) {
                    df = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        result = df.parse(value);
                    } catch (ParseException e2) {
                    }
                }
            }
        }
        return result;
    }
 
}