发表于: 2018-01-19 21:50:52
1 627
今天完成的事
依旧是疯狂敲代码。
敲代码果然是比方案设计爽啊~
搞了个工具类。
JDK1,8都可以用。
我试过了。/
公司的都是适配1.6的。。
package com.ptteng.utils;
import org.apache.http.util.TextUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by ${MIND-ZR} on 2018/1/19.
*这是自己的一个字符串工具类,作用都在注释里了
*/
public class StringUtil {
public static final String EMPTY = "";
private static final String DEFAULT_FILE_PATTERN = "yyyy-MM-dd-HH-mm-ss"; //用于生成文件
private static final double KB = 1024.0;
private static final double MB = 1048576.0;
private static final double GB = 1073741824.0;
public static char chatAt(String pinyin, int index) {
if (pinyin != null && pinyin.length() > 0)
return pinyin.charAt(index);
return ' ';
}
/*
*/
/** 获取字符串宽度 *//*
public static float GetTextWidth(String Sentence, float Size) {
if (isEmpty(Sentence))
return 0;
TextPaint FontPaint = new TextPaint();
FontPaint.setTextSize(Size);
return FontPaint.measureText(Sentence.trim()) + (int) (Size * 0.1); // 留点余地
}
*/
/** 生成一个文件名,不含后缀 */
public static String createFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FILE_PATTERN);
return format.format(date);
}
/**
* 拼接数组
*
* @param array
* @param separator
* @return
*/
public static String join(final ArrayList<String> array,
final String separator) {
StringBuffer result = new StringBuffer();
if (array != null && array.size() > 0) {
for (String str : array) {
result.append(str);
result.append(separator);
}
result.delete(result.length() - 1, result.length());
}
return result.toString();
}
public static String join(final Iterator<String> iter,
final String separator) {
StringBuffer result = new StringBuffer();
if (iter != null) {
while (iter.hasNext()) {
String key = iter.next();
result.append(key);
result.append(separator);
}
if (result.length() > 0)
result.delete(result.length() - 1, result.length());
}
return result.toString();
}
/**
* 判断字符串是否为空
*
* @param str
* @return
*/
public static boolean isEmpty(String str) {
return str == null || str.length() == 0 || str.equalsIgnoreCase("null");
}
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
/**
*
* @param str
* @return
*/
public static String trim(String str) {
return str == null ? EMPTY : str.trim();
}
public static boolean isBlank(String s) {
return TextUtils.isEmpty(s);
}
/**
* 转换文件大小
*
* @param size
* @return
*/
public static String generateFileSize(long size) {
String fileSize;
if (size < KB)
fileSize = size + "B";
else if (size < MB)
fileSize = String.format("%.1f", size / KB) + "KB";
else if (size < GB)
fileSize = String.format("%.1f", size / MB) + "MB";
else
fileSize = String.format("%.1f", size / GB) + "GB";
return fileSize;
}
/** 查找字符串,找到返回,没找到返回空 */
public static String findString(String search, String start, String end) {
int start_len = start.length();
int start_pos = StringUtil.isEmpty(start) ? 0 : search.indexOf(start);
if (start_pos > -1) {
int end_pos = StringUtil.isEmpty(end) ? -1 : search.indexOf(end,
start_pos + start_len);
if (end_pos > -1)
return search.substring(start_pos + start.length(), end_pos);
}
return "";
}
/**
* 判断一个数字是否在一个数字数组中
* @param value
* @param array
* @return
*/
public static boolean iscomprise(int value,int[] array){
int Arraynum[] = array;
// 现在开始对 数据是否存在进行判断
for (int i : Arraynum) {
if(i == value){
return true;
}
}
return false;
}
/**
* 截取字符串
*
* @param search
* 待搜索的字符串
* @param start
* 起始字符串 例如:<title>
* @param end
* 结束字符串 例如:</title>
* @param defaultValue
* @return
*/
public static String substring(String search, String start, String end,
String defaultValue) {
int start_len = start.length();
int start_pos = StringUtil.isEmpty(start) ? 0 : search.indexOf(start);
if (start_pos > -1) {
int end_pos = StringUtil.isEmpty(end) ? -1 : search.indexOf(end,
start_pos + start_len);
if (end_pos > -1)
return search.substring(start_pos + start.length(), end_pos);
else
return search.substring(start_pos + start.length());
}
return defaultValue;
}
/**
* 截取字符串
*
* @param search
* 待搜索的字符串
* @param start
* 起始字符串 例如:<title>
* @param end
* 结束字符串 例如:</title>
* @return
*/
public static String substring(String search, String start, String end) {
return substring(search, start, end, "");
}
/**
* 拼接字符串
*
* @param strs
* @return
*/
public static String concat(String... strs) {
StringBuffer result = new StringBuffer();
if (strs != null) {
for (String str : strs) {
if (str != null)
result.append(str);
}
}
return result.toString();
}
/**
* Helper function for making null strings safe for comparisons, etc.
*
* @return (s == null) ? "" : s;
*/
public static String makeSafe(String s) {
return (s == null) ? "" : s;
}
/**
*
* @Description: 格式化价格
* @param price
* @return 入参
* @return: String 返回类型
* @author: Zengxiaofeng
* @throws:
* @date: 2016-4-15 下午3:06:17
*/
public static String decimalFormat(double price,int num){
String l="";
for(int i=0;i<num;i++){
l=l+"0";
}
DecimalFormat df = new DecimalFormat("######0");
if(!l.equals("")){
df = new DecimalFormat("######0."+l);
}
//DecimalFormat df = new DecimalFormat("######0.00");
return df.format(price);
}
/**
*
* @Description: 随机获取验证码
*/
public static String getVerfiyCode(int lenth){
String str = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
String str2[] = str.split(",");//将字符串以,分割
Random rand = new Random();//创建Random类的对象rand
int index = 0;
String randStr = "";//创建内容为空字符串对象randStr
for (int i=0; i<lenth; ++i){
index = rand.nextInt(str2.length-1);//在0到str2.length-1生成一个伪随机数赋值给index
randStr += str2[index];//将对应索引的数组与randStr的变量值相连接
}
return randStr;
}
/**
* 类似新浪微博内容计数器(中文算一个字符,二个英文算一个字符)
* @param s
* @return
*/
public static int sinaCountWord(String s) {
int i, n = s.length(), l = 0, a = 0, b = 0;
char c;
for (i = 0; i < n; i++) {
c = s.charAt(i);
if (Character.isWhitespace(c)) {
b++;
} else if (c >= 0 && c <= 127) {
// } else if (!Character.isLetter(c)) {
a++;
} else {
l++;
}
}
if (a == 0 && l == 0)
return 0;
return l + (int) Math.ceil((float) (a + b) / 2.0);
}
/**
* 转成MD5
* @param val
* @return
* @throws NoSuchAlgorithmException
*/
public static String getMD5(String val){
try{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(val.getBytes());
byte[] m = md5.digest();//加密
StringBuffer sb = new StringBuffer();
for(int i = 0; i < m.length; i ++){
sb.append(m[i]);
}
return sb.toString();
}
catch(NoSuchAlgorithmException e){
return "";
}
}
/**
* 判断字符串是否纯数字
*
* @author
* @date
* @param str
* @return
*/
public static boolean isNum(String str) {
return str.matches("[0-9]*");
}
/**
* 判断是否是数字或字母
* @param str
* @return
*/
public static boolean isNumberOrLetter(String str,int min,int max){
String reg="^[0-9a-zA-Z]{"+min+","+max+"}$";
return str.matches(reg);
}
/**
* 验证是否为手机号码
* @param str
* @return
*/
public static boolean isMobile(String str){
String numReg = "^1\\d{10}";
boolean result = Pattern.matches(numReg, str);
return result;
}
/**
* 验证邮件格式
* @param email
* @return
*/
public static boolean isEmail(String email){
Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
/**
* 验证固话
* @param tel
* @return
*/
public static boolean isTel(String tel){
/*if(tel.matches("\\d{4}-\\d{8}|\\d{4}-\\d{7}|\\d(3)-\\d(8)")){
return true;
}else if(tel.matches("^[1][3,5]+\\d{9}")){
return true;
}else{
return false;
} */
String reg="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|" +
"(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";
return Pattern.matches(reg, tel);
}
/**
* 校验银行卡卡号
*
* @param cardId
* @return
*/
public static boolean checkBankCard(String cardId) {
char bit = getBankCardCheckCode(cardId
.substring(0, cardId.length() - 1));
return cardId.charAt(cardId.length() - 1) == bit;
}
/**
* 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位
*
* @param nonCheckCodeCardId
* @return
*/
public static char getBankCardCheckCode(String nonCheckCodeCardId) {
int cardLenth = nonCheckCodeCardId.trim().length();
if (nonCheckCodeCardId == null || cardLenth == 0
|| !nonCheckCodeCardId.matches("\\d+")) {
return '-';
}
char[] chs = nonCheckCodeCardId.trim().toCharArray();
int luhmSum = 0;
for (int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
int k = chs[i] - '0';
if (j % 2 == 0) {
k *= 2;
k = k / 10 + k % 10;
}
luhmSum += k;
}
return (luhmSum % 10 == 0) ? '0' : (char) ((10 - luhmSum % 10) + '0');
}
/* *//** 给EditText设置最大输入的数字*//*
public static void setMaxNum(final EditText editText,final int num) {
if(num < 1000) {
editText.setInputType(InputType.TYPE_CLASS_NUMBER); //输入类型
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(3)}); //最大输入长度
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
int snum = Integer.parseInt(s.toString());
if(snum > num) {
editText.setText(num + "");
}
if(snum < 0) {
editText.setText(0 + "");
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
}*/
}
遇到的问题
springboot的bean死活不能注入。
查了资料。
知道这一点非常关键,不知道spring文档里有没有给出说明,如果不知道还真是无从解决。
转:http://blog.csdn.NET/gefangshuai/article/details/50328451,http://412887952-qq-com.iteye.com/blog/2292733
在开发中我们知道Spring Boot默认会扫描启动类同包以及子包下的注解,那么如何进行改变这种扫描包的方式呢,原理很简单就是:
@ComponentScan注解进行指定要扫描的包以及要扫描的类。
这个知识点也太冷了。。。。不科学啊。
降维可以注入。。。真的辣鸡
明天的计划
我要写100个接口!
评论