MD5加密
/**
* 加密工具
* @author Administrator
*
*/
public class MD5Util{
/**
* Md5加密
* @param str
* @param salt
* @return
*/
public static String md5(String str,String pwd){
return new Md5Hash(str,pwd).toString();
}
public static void main(String[] args) {
String password="123456";
System.out.println("Md5加密:"+MD5Util.md5(password, "浩哥4"));
}
}
时间工具类
package com.luohao.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimesUtils {
/**
* @Description 日期对象转成字符串
* @author 浩哥
* @version V1.0
* @param date
* @return
*/
public static String dateToString(Date date){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
/**
* @Description 字符串转成日期对象
* @author浩哥
* @version V1.0
* @param str
* @return
*/
public static Date stringToDate(String str){
Date date = new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
date = sdf.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* @Description 获取当前的时间
* @author浩哥
* @version V1.0
* @return
*/
public static String getCurrentDateStr(){
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(cal.getTime());
}
/*public static void main(String[] args) {
String currentDateStr = getCurrentDateStr();
Date stringToDate = stringToDate(currentDateStr);
String dateToString = dateToString(stringToDate);
System.out.println(dateToString);
}*/
}
转json工具类
package com.luohao.util;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ToJsonUtils {
public static void writes(HttpServletResponse response,Object o){
response.setContentType("text/html;charset=UTF-8");
PrintWriter out;
try {
out = response.getWriter();
out.println(o.toString());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}