Commit 07259995 authored by AlanGao's avatar AlanGao
Browse files

update

parent 458409b4
package com.jsh.util;
import com.jsh.base.Log;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import com.jsh.base.Log;
/**
* 获取应用系统路径
*
* @author jishenghua
* @qq 7 5 2 7 1 8 9 2 0
*/
public class PathTool
{
public class PathTool {
/**
* 获取WEB-INF的绝对路径
*
* @return
*/
public static String getWebinfPath()
{
public static String getWebinfPath() {
String webinfPath = "";
//获取URL对象
URL url = PathTool.class.getClassLoader().getResource("");
try
{
try {
//获取路径
webinfPath = url.toURI().getPath();
//截取路径到WEB-INF结束
// webinfPath = path.substring(0, path.indexOf("/WEB-INF") + 8);
}
catch (URISyntaxException e)
{
} catch (URISyntaxException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>路径获取异常", e);
}
return webinfPath;
......@@ -39,21 +36,18 @@ public class PathTool
/**
* 获取webapp的绝对路径
*
* @return
*/
public static String getWebappPath()
{
public static String getWebappPath() {
//先获取工程路径
String projectPath = getProjectPath();
//获取工程路径的上级路径
File f = new File(projectPath);
//路径不存在就返回
if (!f.exists())
{
if (!f.exists()) {
return projectPath;
}
else
{
} else {
//返回webapp路径
return f.getParent();
}
......@@ -61,23 +55,20 @@ public class PathTool
/**
* 获取工程的绝对路径
*
* @return
*/
public static String getProjectPath()
{
public static String getProjectPath() {
String projectPath = "";
//获取URL对象
URL url = PathTool.class.getClassLoader().getResource("");
String path = null;
try
{
try {
//获取路径
path = url.toURI().getPath();
//截取webapp路径
projectPath = path.substring(0, path.indexOf("/WEB-INF"));
}
catch (URISyntaxException e)
{
} catch (URISyntaxException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>路径获取异常", e);
}
return projectPath;
......
......@@ -6,15 +6,16 @@ import java.util.Set;
/**
* 根据搜索条件拼装成查询hql语句
*
* @author jishenghua qq:752718920
*/
public class SearchConditionUtil
{
public class SearchConditionUtil {
//拼接字符串的前缀空格字符串
private static final String emptyPrefix = " and ";
/**
* 根据搜索条件自动拼接成hql搜索语句
*
* @param condition 搜索条件 规则:
* 1、类型 n--数字 s--字符串
* 2、属性 eq--等于 neq--不等于 like--像'%XX%' llike--左像'%XX' rlike--右像'XX%' in--包含 gt--大于 gteq--大于等于 lt--小于 lteq--小于等于
......@@ -29,37 +30,33 @@ public class SearchConditionUtil
* condition.put("description_s_order", "desc");
* @return 封装后的字符串
*/
public static String getCondition(Map<String,Object> condition)
{
public static String getCondition(Map<String, Object> condition) {
StringBuffer hql = new StringBuffer();
Set<String> key = condition.keySet();
String groupbyInfo = "";
String orderInfo = "";
for(String keyInfo:key)
{
for (String keyInfo : key) {
/*
* 1、数组为三个 第一个为对象实例的字段 第二个为字段类型 第三个为属性
* 2、根据分解后的数组拼接搜索条件
*/
Object valueInfo = condition.get(keyInfo);
if(null != valueInfo &&valueInfo.toString().length()>0)
{
if (null != valueInfo && valueInfo.toString().length() > 0) {
String[] searchCondition = keyInfo.split("_");
if(searchCondition[1].equals("n"))
if (searchCondition[1].equals("n"))
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + valueInfo);
else if(searchCondition[1].equals("s"))
{
if(searchCondition[2].equals("like"))
else if (searchCondition[1].equals("s")) {
if (searchCondition[2].equals("like"))
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + "'%" + valueInfo + "%'");
else if(searchCondition[2].equals("llike"))
else if (searchCondition[2].equals("llike"))
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + "'%" + valueInfo + "'");
else if(searchCondition[2].equals("rlike"))
else if (searchCondition[2].equals("rlike"))
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + "'" + valueInfo + "%'");
else if(searchCondition[2].equals("in"))
else if (searchCondition[2].equals("in"))
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + "(" + valueInfo + ")");
else if(searchCondition[2].equals("order"))
else if (searchCondition[2].equals("order"))
orderInfo = " order by " + searchCondition[0] + " " + valueInfo;
else if(searchCondition[2].equals("gb"))
else if (searchCondition[2].equals("gb"))
groupbyInfo = " group by " + searchCondition[0];
else
hql.append(emptyPrefix + searchCondition[0] + getType(searchCondition[2]) + "'" + valueInfo + "'");
......@@ -72,47 +69,46 @@ public class SearchConditionUtil
/**
* 获取指定类型的符号
* 属性 eq--等于 neq--不等于 like--像 in--包含 gt--大于 gteq--大于等于 lt--小于 lteq--小于等于 order--value desc asc
*
* @param type
* @return 类型字符串
*/
private static String getType(String type)
{
private static String getType(String type) {
String typeStr = "";
if(type.equals("eq"))
if (type.equals("eq"))
typeStr = " = ";
else if(type.equals("neq"))
else if (type.equals("neq"))
typeStr = " != ";
else if(type.equals("like"))
else if (type.equals("like"))
typeStr = " like ";
else if(type.equals("llike"))
else if (type.equals("llike"))
typeStr = " like ";
else if(type.equals("rlike"))
else if (type.equals("rlike"))
typeStr = " like ";
else if(type.equals("in"))
else if (type.equals("in"))
typeStr = " in ";
else if(type.equals("gt"))
else if (type.equals("gt"))
typeStr = " > ";
else if(type.equals("gteq"))
else if (type.equals("gteq"))
typeStr = " >= ";
else if(type.equals("lt"))
else if (type.equals("lt"))
typeStr = " < ";
else if(type.equals("lteq"))
else if (type.equals("lteq"))
typeStr = " <= ";
else if(type.equals("order"))
else if (type.equals("order"))
typeStr = " order ";
else if(type.equals("gy"))
else if (type.equals("gy"))
typeStr = " group by ";
else
typeStr = "unknown";
return typeStr;
}
public static void main(String[] args)
{
public static void main(String[] args) {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("supplier_s_like", "aaa");
condition.put("contacts_s_llike", "186");
condition.put("contacts_s_rlike", "186");
......
package com.jsh.util;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**
* 用户登录session处理类
* 过滤session是否超时
*
* @author jishenghua qq_752718920
* @version [版本号, 2012-3-6]
* @see [相关类/方法]
* @since
*/
public class SessionFilter implements Filter
{
public class SessionFilter implements Filter {
/**
* 初始化过滤器 暂不处理
* 重载方法
*
* @param arg0
* @throws ServletException
*/
public void init(FilterConfig arg0)
throws ServletException
{
throws ServletException {
}
/**
* 判断用户session是否存在 不存在则跳转到登录页面
* 重载方法
*
* @param srequest
* @param sresponse
* @param chain
......@@ -44,8 +40,7 @@ public class SessionFilter implements Filter
* @throws ServletException
*/
public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain)
throws IOException, ServletException
{
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) srequest;
HttpServletResponse response = (HttpServletResponse) sresponse;
HttpSession session = request.getSession();
......@@ -54,7 +49,7 @@ public class SessionFilter implements Filter
String path = request.getContextPath();
String requestURl = request.getRequestURI();
if(requestURl.contains("/pages") &&null != session.getAttribute("user"))
if (requestURl.contains("/pages") && null != session.getAttribute("user"))
chain.doFilter(request, response);
else
response.sendRedirect(path + "/logout.jsp");
......@@ -63,8 +58,7 @@ public class SessionFilter implements Filter
/**
* 销毁过滤器
*/
public void destroy()
{
public void destroy() {
}
}
......@@ -2,25 +2,25 @@ package com.jsh.util;
/**
* 定义供应商、客户管理常量
*
* @author jishenghua
*/
public interface SupplierConstants
{
public interface SupplierConstants {
/**
* 公共常量
*
* @author jishenghua
*/
public class Common
{
public class Common {
}
/**
* 常量--导入导出excel表格业务相关
*
* @author jishenghua
*/
public class BusinessForExcel
{
public class BusinessForExcel {
/**
* 名称
*/
......
......@@ -3,6 +3,7 @@ package com.jsh.util;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
......@@ -11,95 +12,100 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Pattern;
import java.math.BigInteger;
/**
* 工具类
*
* @author jishenghua qq:7-5-2-7-1-8-9-2-0
*/
public class Tools
{
public class Tools {
/**
* 获得32位唯一序列号
*
* @return 32为ID字符串
*/
public static String getUUID_32()
{
public static String getUUID_32() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
/**
* 获得当天时间,格式为yyyy-MM-dd
*
* @return 格式化后的日期格式
*/
public static String getNow()
{
public static String getNow() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
/**
* 获取当前月 yyyy-MM
*
* @return
*/
public static String getCurrentMonth()
{
public static String getCurrentMonth() {
return new SimpleDateFormat("yyyy-MM").format(new Date());
}
/**
* 获取指定日期格式 yyyy-MM-dd
*
* @return
*/
public static String getCurrentMonth(Date date)
{
public static String getCurrentMonth(Date date) {
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
/**
* 获得当天时间,格式为yyyyMMddHHmmss
*
* @return 格式化后的日期格式
*/
public static String getNow2(Date date)
{
public static String getNow2(Date date) {
return new SimpleDateFormat("yyyyMMddHHmmss").format(date);
}
/**
* 获得当天时间,格式为yyyy-MM-dd HH:mm:ss
*
* @return 格式化后的日期格式
*/
public static String getNow3()
{
public static String getNow3() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
/**
* 获得指定时间,格式为yyyy-MM-dd HH:mm:ss
*
* @return 格式化后的日期格式
*/
public static String getCenternTime(Date date)
{
public static String getCenternTime(Date date) {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
}
/**
* 获得指定时间,格式为mm:ss
*
* @return 格式化后的日期格式
*/
public static String getTimeInfo(Date date)
{
public static String getTimeInfo(Date date) {
return new SimpleDateFormat("mm:ss").format(date);
}
/**
* 获取当前日期是星期几
* return 星期几
*/
public static String getWeekDay()
{
public static String getWeekDay() {
Calendar c = Calendar.getInstance(Locale.CHINA);
c.setTime(new Date());
int day=c.get(Calendar.DAY_OF_WEEK);
int day = c.get(Calendar.DAY_OF_WEEK);
String weekDay = "";
switch (day)
{
switch (day) {
case 1:
weekDay = "星期日";
break;
......@@ -126,24 +132,26 @@ public class Tools
}
return weekDay;
}
/**
* 判断字符串是否全部为数字
*
* @param accountWaste
* @return boolean值
*/
public static boolean checkStrIsNum(String checkStr)
{
if(checkStr == null || checkStr.length() ==0)
public static boolean checkStrIsNum(String checkStr) {
if (checkStr == null || checkStr.length() == 0)
return false;
return Pattern.compile("^[0-9]*.{1}[0-9]*$").matcher(checkStr).matches();
// return Pattern.compile(":^[0-9]+(.[0-9])*$").matcher(checkStr).matches();
}
/**
* 获得前一天的时间
*
* @return 前一天日期
*/
public static String getPreviousDate()
{
public static String getPreviousDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
return new SimpleDateFormat("yyyy-MM").format(cal.getTime());
......@@ -151,38 +159,40 @@ public class Tools
/**
* 截取字符串长度
*
* @param beforeStr
* @param cutLeng
* @return 截取后的字符串
*/
public static String subStr(String beforeStr,int cutLeng){
if(beforeStr.length()>cutLeng)
return beforeStr.substring(0,cutLeng)+ "..." ;
return beforeStr ;
public static String subStr(String beforeStr, int cutLeng) {
if (beforeStr.length() > cutLeng)
return beforeStr.substring(0, cutLeng) + "...";
return beforeStr;
}
/**
* 生成随机字符串,字母和数字混合
*
* @return 组合后的字符串 ^[0-9a-zA-Z]
*/
public static String getRandomChar(){
public static String getRandomChar() {
//生成一个0、1、2的随机数字
int rand = (int)Math.round(Math.random() * 1);
int rand = (int) Math.round(Math.random() * 1);
long itmp = 0;
char ctmp = '\u0000';
switch (rand)
{
switch (rand) {
//生成大写字母 + 1000以内数字
case 1:
itmp = Math.round(Math.random() * 25 + 65);
ctmp = (char)itmp;
return String.valueOf(ctmp) + (int)Math.random()*1000;
ctmp = (char) itmp;
return String.valueOf(ctmp) + (int) Math.random() * 1000;
//生成小写字母
case 2:
itmp = Math.round(Math.random() * 25 + 97);
ctmp = (char)itmp;
return String.valueOf(ctmp)+ (int)Math.random()*1000;
ctmp = (char) itmp;
return String.valueOf(ctmp) + (int) Math.random() * 1000;
//生成数字
default :
default:
itmp = Math.round(Math.random() * 1000);
return itmp + "";
}
......@@ -190,41 +200,39 @@ public class Tools
/**
* 判断首字母以数字开头,字符串包括数字、字母%以及空格
*
* @param str 检查字符串
* @return 是否以数字开头
*/
public static boolean CheckIsStartWithNum(String str)
{
public static boolean CheckIsStartWithNum(String str) {
return Pattern.compile("^[0-9][a-zA-Z0-9%,\\s]*$").matcher(str).matches();
}
/**
* 判断首字母以","开头,字符串包括数字、字母%以及空格
*
* @param str 检查字符串
* @return 是否以数字开头
*/
public static boolean CheckIsStartWithSpec(String str)
{
public static boolean CheckIsStartWithSpec(String str) {
return Pattern.compile("^[,][a-zA-Z0-9%,\\s]*$").matcher(str).matches();
}
/**
* 字符转码
*
* @param aValue
* @return
* @see 转码后的字符串
*/
public static String encodeValue(String aValue)
{
if(aValue.trim().length() ==0)
{
public static String encodeValue(String aValue) {
if (aValue.trim().length() == 0) {
return "";
}
String valueAfterTransCode = null;
try
{
try {
valueAfterTransCode = URLEncoder.encode(aValue, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
} catch (UnsupportedEncodingException e) {
e.getMessage();
}
return valueAfterTransCode;
......@@ -232,23 +240,19 @@ public class Tools
/**
* 字符转码
*
* @param aValue
* @return
* @see 转码后的字符串
*/
public static String decodeValue(String aValue)
{
if(aValue.trim().length() ==0)
{
public static String decodeValue(String aValue) {
if (aValue.trim().length() == 0) {
return "";
}
String valueAfterTransCode = null;
try
{
try {
valueAfterTransCode = URLDecoder.decode(aValue, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
} catch (UnsupportedEncodingException e) {
e.getMessage();
}
return valueAfterTransCode;
......@@ -256,28 +260,25 @@ public class Tools
/**
* 去除str中的'
*
* @param str
* @return 除去'后的字符串
* @see [类、类#方法、类#成员]
*/
public static String afterDealStr(String str)
{
public static String afterDealStr(String str) {
return str.replace("'", "");
}
/**
* 获取用户IP地址(停用)
*
* @return 用户IP
* @see [类、类#方法、类#成员]
*/
public static String getCurrentUserIP()
{
try
{
public static String getCurrentUserIP() {
try {
return InetAddress.getLocalHost().getHostAddress();
}
catch (UnknownHostException e)
{
} catch (UnknownHostException e) {
e.printStackTrace();
return "127.0.0.1";
}
......@@ -285,6 +286,7 @@ public class Tools
/**
* 从Request对象中获得客户端IP,处理了HTTP代理服务器和Nginx的反向代理截取了ip
*
* @param request
* @return ip
*/
......@@ -304,7 +306,7 @@ public class Tools
if (realIp.equals(forwarded)) {
ip = realIp;
} else {
if(forwarded != null){
if (forwarded != null) {
forwarded = forwarded.split(",")[0];
}
ip = realIp + "/" + forwarded;
......@@ -315,14 +317,14 @@ public class Tools
/**
* 转化前台批量传入的ID值
*
* @param data
* @return 转化后的ID值数组
*/
public static int[] changeDataForm(String data)
{
public static int[] changeDataForm(String data) {
String[] dataStr = data.split(",");
int[] dataInt = new int[dataStr.length];
for(int i = 0 ;i < dataStr.length;i ++)
for (int i = 0; i < dataStr.length; i++)
dataInt[i] = Integer.parseInt(dataStr[i]);
return dataInt;
}
......@@ -330,40 +332,29 @@ public class Tools
/**
* 解决导出文件中文乱码问题firefox和ie下中文乱码
*/
public static String changeUnicode(String fileName,String browserType)
{
public static String changeUnicode(String fileName, String browserType) {
String returnFileName = "";
try
{
if(browserType.equalsIgnoreCase("MSIE"))
{
try {
if (browserType.equalsIgnoreCase("MSIE")) {
returnFileName = URLEncoder.encode(fileName, "ISO8859-1");
returnFileName = returnFileName.replace(" ","%20");
if (returnFileName.length() > 150)
{
returnFileName = returnFileName.replace(" ", "%20");
if (returnFileName.length() > 150) {
returnFileName = new String(fileName.getBytes("GB2312"), "ISO8859-1");
returnFileName = returnFileName.replace(" ", "%20");
}
}
else if(browserType.equalsIgnoreCase("Firefox"))
{
returnFileName = new String(fileName.getBytes("ISO8859-1"),"ISO8859-1");
} else if (browserType.equalsIgnoreCase("Firefox")) {
returnFileName = new String(fileName.getBytes("ISO8859-1"), "ISO8859-1");
returnFileName = returnFileName.replace(" ", "%20");
}
else
{
} else {
returnFileName = URLEncoder.encode(fileName, "ISO8859-1");
returnFileName = returnFileName.replace(" ","%20");
if (returnFileName.length() > 150)
{
returnFileName = returnFileName.replace(" ", "%20");
if (returnFileName.length() > 150) {
returnFileName = new String(returnFileName.getBytes("GB2312"), "ISO8859-1");
returnFileName = returnFileName.replace(" ", "%20");
}
}
}
catch (UnsupportedEncodingException e)
{
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return returnFileName;
......@@ -371,11 +362,11 @@ public class Tools
/**
* 写理财日志内容转化特殊字符
*
* @param str 需要转化的字符
* @return 转化后的字符
*/
public static String htmlspecialchars(String str)
{
public static String htmlspecialchars(String str) {
str = str.replaceAll("&", "&amp;");
str = str.replaceAll("<", "&lt;");
str = str.replaceAll(">", "&gt;");
......@@ -385,21 +376,21 @@ public class Tools
/**
* 根据消费日期获取消费月
*
* @param consumeDate 消费日期
* @return 返回消费月信息
*/
public static String getConsumeMonth(String consumeDate)
{
return consumeDate.substring(0,7);
public static String getConsumeMonth(String consumeDate) {
return consumeDate.substring(0, 7);
}
/**
* 获取当前日期的前XX个月
*
* @param 之前的第几个月
* @return 前XX个月字符串
*/
public static String getBeforeMonth(int beforeMonth)
{
public static String getBeforeMonth(int beforeMonth) {
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -beforeMonth);
return new SimpleDateFormat("yyyy-MM").format(c.getTime());
......@@ -408,28 +399,24 @@ public class Tools
/**
* 获取email用户姓名
*
* @param args
*/
public static String getEmailUserName(String emailAddress)
{
return emailAddress.substring(0,emailAddress.lastIndexOf("@"));
public static String getEmailUserName(String emailAddress) {
return emailAddress.substring(0, emailAddress.lastIndexOf("@"));
}
/**
* 获取中文编码,邮件附件乱码问题解决
*
* @param str
* @return
*/
public static String getChineseString(String emailAttchmentTitle)
{
if(emailAttchmentTitle!=null&&!emailAttchmentTitle.equals(""))
{
try
{
return new String(emailAttchmentTitle.getBytes(),"ISO-8859-1");
}
catch (UnsupportedEncodingException e)
{
public static String getChineseString(String emailAttchmentTitle) {
if (emailAttchmentTitle != null && !emailAttchmentTitle.equals("")) {
try {
return new String(emailAttchmentTitle.getBytes(), "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
......@@ -438,94 +425,88 @@ public class Tools
/**
* 判断userTel是否合法,userTel只能是数字
*
* @param userTel
* @return true 合法 false不合法
*/
public static boolean isTelNumber(String userTel)
{
String reg_phone="^(\\(\\d{3,4}\\)|\\d{3,4}-)?\\d{7,8}$";
String reg_tel="^(1[0-9][0-9]|1[0-9][0|3|6|8|9])\\d{8}$";
boolean b_phpne=Pattern.compile(reg_phone).matcher(userTel).matches();
boolean b_tel=Pattern.compile(reg_tel).matcher(userTel).matches();
public static boolean isTelNumber(String userTel) {
String reg_phone = "^(\\(\\d{3,4}\\)|\\d{3,4}-)?\\d{7,8}$";
String reg_tel = "^(1[0-9][0-9]|1[0-9][0|3|6|8|9])\\d{8}$";
boolean b_phpne = Pattern.compile(reg_phone).matcher(userTel).matches();
boolean b_tel = Pattern.compile(reg_tel).matcher(userTel).matches();
return (b_phpne || b_tel);
}
/**
* 模糊判断电话号码是否合法,只能是数字
*
* @param macAddress
* @return
*/
public static boolean isTelNumberBySlur(String userTel)
{
public static boolean isTelNumberBySlur(String userTel) {
return Pattern.compile("^([\\s0-9]{0,12}$)").matcher(userTel).matches();
}
/**
* 获取当前时间的字符串类型
*
* @return 处理后的字符串类型
*/
public static String getNowTime()
{
public static String getNowTime() {
return new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());
}
/**
* 开打指定文件
*
* @param filePath 文件的绝对路径
*/
public static void openFile(String filePath)
{
public static void openFile(String filePath) {
String viewFilePath = filePath.replace("\\", "/");
// Runtime.getRuntime().exec("cmd /c start "+filePath);
// 解决路径中带空格问题
Runtime r = Runtime.getRuntime();
String[] cmdArray = new String[] { "cmd.exe", "/c", viewFilePath };
try
{
String[] cmdArray = new String[]{"cmd.exe", "/c", viewFilePath};
try {
r.exec(cmdArray);
}
catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 判断字符串中是否含有中文
* @author jishenghua
*
* @param str
* @return
* @author jishenghua
*/
public static boolean isContainsChinese(String str)
{
public static boolean isContainsChinese(String str) {
return Pattern.compile("[\u4e00-\u9fa5]").matcher(str).matches();
}
/**
* 过滤html文件中的文本
*
* @param content
* @return过滤后的文本
*/
public static String filterText(String content)
{
return content.replace("/<(?:.|\\s)*?>/g","");
public static String filterText(String content) {
return content.replace("/<(?:.|\\s)*?>/g", "");
}
/**
* 去掉字符串中所有符号,不论是全角,还是半角的,或是货币符号或者空格等
* @author jishenghua
*
* @param s
* @return
*
* @author jishenghua
*/
public static String removeSymbolForString(String s)
{
public static String removeSymbolForString(String s) {
StringBuffer buffer = new StringBuffer();
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if ((chars[i] >= 19968 && chars[i] <= 40869) || (chars[i] >= 97 && chars[i] <= 122) || (chars[i] >= 65 && chars[i] <= 90))
{
for (int i = 0; i < chars.length; i++) {
if ((chars[i] >= 19968 && chars[i] <= 40869) || (chars[i] >= 97 && chars[i] <= 122) || (chars[i] >= 65 && chars[i] <= 90)) {
buffer.append(chars[i]);
}
}
......@@ -534,12 +515,12 @@ public class Tools
/**
* 获取一个字符串的MD5
*
* @param msg
* @return 加密后的MD5字符串
* @throws NoSuchAlgorithmException
*/
public static String md5Encryp(String msg) throws NoSuchAlgorithmException
{
public static String md5Encryp(String msg) throws NoSuchAlgorithmException {
// 生成一个MD5加密计算摘要
MessageDigest md = MessageDigest.getInstance("MD5");
// 计算md5函数
......@@ -549,28 +530,27 @@ public class Tools
/**
* 处理字符串null值
*
* @param beforeStr 处理前字符串
* @return 处理后的字符串
*/
public static String dealNullStr(String beforeStr)
{
if(null == beforeStr || beforeStr.length()==0)
public static String dealNullStr(String beforeStr) {
if (null == beforeStr || beforeStr.length() == 0)
return "";
return beforeStr;
}
/**
* 使用参数Format将字符串转为Date
* @author jishenghua
*
* @param strDate
* @param pattern
* @return
* @throws ParseException
*
* @author jishenghua
*/
public static Date parse(String strDate, String pattern)
throws ParseException
{
throws ParseException {
return new SimpleDateFormat(pattern).parse(strDate);
}
......@@ -584,23 +564,18 @@ public class Tools
// return content.matches("/<img(?:.|\\s)*?>/g");
// }
public static void main(String[] args)
{
public static void main(String[] args) {
String aa = "的付的反对法的发的说法";
char[] bb = aa.toCharArray();
for(char c : bb)
{
for (char c : bb) {
System.out.println(c);
}
System.out.println(getBeforeMonth(1));
try
{
try {
System.out.println(md5Encryp("guest"));
System.out.println(md5Encryp("admin"));
}
catch (NoSuchAlgorithmException e)
{
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -608,8 +583,7 @@ public class Tools
String value = "2333";
System.out.println(checkStrIsNum(value));
for(int i = 0 ;i < 100;i ++)
{
for (int i = 0; i < 100; i++) {
System.out.print(getRandomChar() + " || ");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment