| | |
| | | } |
| | | 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) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 中英文字符长度控制 |
| | | * @param str |
| | | * @param maxLength |
| | | * @return |
| | | */ |
| | | public static String subStringCN(final String str, final int maxLength) { |
| | | if (str == null) { |
| | | return str; |
| | | } |
| | | String suffix = "..."; |
| | | int suffixLen = suffix.length(); |
| | | |
| | | final StringBuffer sbuffer = new StringBuffer(); |
| | | final char[] chr = str.trim().toCharArray(); |
| | | int len = 0; |
| | | for (int i = 0; i < chr.length; i++) { |
| | | |
| | | if (chr[i] >= 0xa1) { |
| | | len += 2; |
| | | } else { |
| | | len++; |
| | | } |
| | | } |
| | | |
| | | if(len<=maxLength){ |
| | | return str; |
| | | } |
| | | |
| | | len = 0; |
| | | for (int i = 0; i < chr.length; i++) { |
| | | |
| | | if (chr[i] >= 0xa1) { |
| | | len += 2; |
| | | if (len + suffixLen > maxLength) { |
| | | break; |
| | | }else { |
| | | sbuffer.append(chr[i]); |
| | | } |
| | | } else { |
| | | len++; |
| | | if (len + suffixLen > maxLength) { |
| | | break; |
| | | }else { |
| | | sbuffer.append(chr[i]); |
| | | } |
| | | } |
| | | } |
| | | sbuffer.append(suffix); |
| | | return sbuffer.toString(); |
| | | } |
| | | public static boolean isNumericZidai(String str) { |
| | | for (int i = 0; i < str.length(); i++) { |
| | | System.out.println(str.charAt(i)); |
| | | if (!Character.isDigit(str.charAt(i))) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |