| | |
| | | package com.moral.common.util; |
| | | |
| | | import com.mysql.jdbc.TimeUtil; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import org.apache.commons.lang3.Conversion; |
| | | |
| | | /** |
| | | * |
| | | * 功能描述: string 工具类 |
| | | * @author: fengxiang |
| | | * @date: 2018/7/30 10:53 |
| | | */ |
| | | public class StringUtils { |
| | | public static final char UNDERLINE = '_'; |
| | | public static final String NULL = "null"; |
| | | |
| | | /** |
| | | * 驼峰格式字符串转换为下划线格式字符串 |
| | |
| | | return sb.toString(); |
| | | } |
| | | public static boolean isNullOrEmpty(String toTest) { |
| | | return toTest == null || toTest.length() == 0; |
| | | return toTest == null || toTest.length() == 0 || NULL.equals(toTest); |
| | | } |
| | | public static Object stringToObject4Type(Class<?> type,String value) throws Exception{ |
| | | Object result = value; |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |