package com.common.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//import jxl.Cell;
//import jxl.Sheet;
//import jxl.Workbook;
//import jxl.format.Colour;
//import jxl.write.Alignment;
//import jxl.write.Border;
//import jxl.write.BorderLineStyle;
//import jxl.write.Label;
//import jxl.write.VerticalAlignment;
//import jxl.write.WritableCellFormat;
//import jxl.write.WritableFont;
//import jxl.write.WritableSheet;
//import jxl.write.WritableWorkbook;
//import org.apache.commons.io.FileUtils;
import org.apache.ibatis.annotations.Param;
/**
* 公共工具类
* @author 李建
*/
public class PublicUtil {
/**
* @param index 截取字符串下标
* @param str 字符串
* @param endStr 添加结尾字符串 例如"..."
* @return
*/
public static String subStr(String str, int index, String endStr){
if(str == null || "".equals(str)){
return "";
}
if(str.length()<=index){
return str;
}
return str.substring(0,index)+endStr;
}
/**
* 去尾部字符
* @param param
* @param endWithStr
* @return
*/
public static String delEndString(String param,String endWithStr){
if("".equals(getStrValue(param, ""))){
return param;
}
if (param.endsWith(endWithStr)) {
param = param.substring(0, param.length() - endWithStr.length());
}
return param;
}
/**
* 去头部字符
* @param param
* @param endWithStr
* @return
*/
public static String delStartString(String param,String startWithStr){
if("".equals(getStrValue(param, ""))){
return param;
}
if (param.startsWith(startWithStr)) {
param = param.substring(startWithStr.length(), param.length());
}
return param;
}
/**
* 转string类型
* @param param
* @param value
* @return
*/
public static String getStrValue(Object param,String value){
if(param == null){
return value;
}
if("".equals(param.toString()) || "null".equals(param.toString())){
return value;
}
return param.toString().trim();
}
/**
* 转double类型
* @param param
* @param value
* @return
*/
public static Double getDoubleValue(Object param,Double value){
if(param == null){
return value;
}
if("".equals(param.toString()) || "null".equals(param.toString())){
return value;
}
return Double.parseDouble(param.toString());
}
/**
* 格式化带小数点的数字
* @param param
* @param format
* @return
*/
public static String decimalFormat(double param,String format){
DecimalFormat df = new DecimalFormat(format);
return df.format(param);
}
/**
* 转int类型
* @param param
* @param value
* @return
*/
public static int getIntValue(Object param,int value){
if(param == null){
return value;
}
if("".equals(param.toString()) || "null".equals(param.toString())){
return value;
}
if(param.toString().contains(".")){
return (int)Double.parseDouble(param.toString());
}
return Integer.parseInt(param.toString());
}
/**
* 去空格
* @param str
* @return
*/
public static String deleteIt(String str) {
if(str == null || "".equals(str)){
return "";
}
str = str.trim();
str = str.replaceAll(" ", "");
return str;
}
/**
* 按照自定义格式字符串转日期
* @author 李建
* @param value
* @param format
* @return
*/
public static Date str2FormatDate(String value, String format){
if(value == null || value.equals("")){
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
return sdf.parse(value);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
/**
* 将类似于"0531,0532,0533"这样的以逗号等分隔符连接的字符串转换为字符数组
* @author 李建
* @param str
* @param delimitor 如果为空或"",则默认为逗号
* @return
*/
public static String[] str2Array(String str, String delimitor){
if(null == str || str.equals(""))
{
return null;
}
if(null == delimitor || delimitor.equals(""))
{
delimitor = ",";
}
return str.split(delimitor);
}
/**
* 按照自定义格式日期转字符串
* @param date
* @param format
* @param value
* @return
*/
public static String date2formatStr(Date date,String format,String value){
if(date == null){
return value;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
/**
* 按照自定义格式日期转字符串,尾部可追加字符
* @param date
* @param format
* @param appendStr
* @param value
* @return
*/
public static String date2formatStr(Date date,String format,String appendStr,String value){
if(date == null){
return value;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
String str = sdf.format(date) + appendStr;
return str;
}
/**
* 按照自定义格式日期转字符串
* @param date
* @param format
* @param value
* @return
*/
public static Date str2formatDate(Object date,String format){
String value = getStrValue(date, "");
if("".equals(value)){
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
return sdf.parse(value);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static Date DateFormat(Date date,String format){
if(date == null){
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
String str = sdf.format(date);
try {
return sdf.parse(str);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
/**
* 验证取值范围
* @param param
* @param bigValue
* @param smallValue
* @return
*/
public static boolean checkNumberScope(Object param,Object bigValue,Object smallValue) {
double value = getDoubleValue(param, 0.0);
double big = getDoubleValue(bigValue, 0.0);
double small = getDoubleValue(smallValue, 0.0);
if(value <= big && value >= small){
return true;
}
return false;
}
/**
* 获取某日期前,后若干天的日期
* @param format 日期格式
* @param date 某一日期
* @param index 前或者后的天数
* @return
*/
public static String getOtherDate(String format,Date date,int index){
if(date == null){
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
Calendar c=Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE,index);
return sdf.format(c.getTime());
}
/**
* 获取某日期前,后若干天的日期
* @param format 日期格式
* @param date 某一日期
* @param index 前或者后的天数
* @return
*/
public static Date getOtherDate(Date date,int index){
if(date == null){
return null;
}
Calendar c=Calendar.getInstance();
c.setTime(date);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springmvc_fileupload_demo.rar (48个子文件)
springmvc_fileupload_demo
.externalToolBuilders
org.eclipse.wst.jsdt.core.javascriptValidator (1).launch 548B
pom.xml 6KB
target
test-classes
m2e-jee
web-resources
META-INF
maven
spring_ajax_fileupload_demo
spring_ajax_fileupload_demo
pom.xml 6KB
pom.properties 320B
springmvc_fileupload_demo
springmvc_fileupload_demo
pom.xml 6KB
pom.properties 316B
fastDevPlatform_easyui
fastDevPlatform_easyui
pom.xml 6KB
pom.properties 314B
MANIFEST.MF 114B
surefire
classes
system.properties 69B
spring-mvc.xml 3KB
log4j.properties 2KB
com
fileUpload
controller
FileController.class 4KB
entity
Obj.class 728B
common
util
PublicUtil.class 17KB
applicationContext.xml 973B
maven-archiver
pom.properties 143B
.settings
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
com.genuitec.eclipse.core.prefs 115B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.core.resources.prefs 132B
org.eclipse.wst.common.component 539B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 508B
org.eclipse.jdt.core.prefs 664B
src
main
webapp
css
index.css 645B
images
add.png 1KB
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 2KB
classes
lib
jackson-all-1.9.0.jar 1.05MB
json-lib-2.4-jdk15.jar 155KB
index.html 2KB
js
jquery
jquery-1.8.3.min.js 91KB
imageUploadPreview.js 3KB
upload_success.jsp 635B
errors
error_fileupload.jsp 99B
upload_files
images
java
system.properties 69B
spring-mvc.xml 3KB
log4j.properties 2KB
com
fileUpload
controller
FileController.java 3KB
entity
Obj.java 380B
common
util
PublicUtil.java 42KB
applicationContext.xml 973B
.project 2KB
.mymetadata 356B
.classpath 738B
.myeclipse
共 48 条
- 1
资源评论
- shh1981012017-04-13还行吧,有一定的参考价值
- chennnm2017-04-24下载下来的东西乱码
明湖居士2018
- 粉丝: 111
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功