`
收藏列表
标题 标签 来源
Java读写Excel生成Workbook excel,poi Java读写Excel之POI超入门
//生成Workbook
HSSFWorkbook wb = new HSSFWorkbook();

//添加Worksheet(不添加sheet时生成的xls文件打开时会报错)
@SuppressWarnings("unused")
Sheet sheet1 = wb.createSheet();
@SuppressWarnings("unused")
Sheet sheet2 = wb.createSheet();
@SuppressWarnings("unused")
Sheet sheet3 = wb.createSheet("new sheet");
@SuppressWarnings("unused")
Sheet sheet4 = wb.createSheet("rensanning");

//保存为Excel文件
FileOutputStream out = null;

try {
    out = new FileOutputStream("c:\\text.xls");
    wb.write(out);		
} catch (IOException e) {
    System.out.println(e.toString());
} finally {
    try {
        out.close();
    } catch (IOException e) {
        System.out.println(e.toString());
    }
}	
JAVA处理日期时间常用方法总结 JAVA处理日期时间常用方法总结


JAVA处理日期时间常用方法:

1.java.util.Calendar
Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。瞬间可用毫秒值来表示,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量。

例:
Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
cal.add(Calendar.DAY_OF_MONTH, -1);//取当前日期的前一天.

cal.add(Calendar.DAY_OF_MONTH, +1);//取当前日期的后一天.

//通过格式化输出日期
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");

System.out.println("Today is:"+format.format(Calendar.getInstance().getTime()));

System.out.println("yesterday is:"+format.format(cal.getTime()));

得到2007-12-25日期:

Calendar calendar = new GregorianCalendar(2007, 11, 25,0,0,0);
Date date = calendar.getTime();
System.out.println("2007 Christmas is:"+format.format(date));

java月份是从0-11,月份设置时要减1.

GregorianCalendar构造方法参数依次为:年,月-1,日,时,分,秒.

取日期的部分:

int year =calendar.get(Calendar.YEAR);

int month=calendar.get(Calendar.MONTH)+1;

int day =calendar.get(Calendar.DAY_OF_MONTH);

int hour =calendar.get(Calendar.HOUR_OF_DAY);

int minute =calendar.get(Calendar.MINUTE);

int seconds =calendar.get(Calendar.SECOND);

取月份要加1.

判断当前月份的最大天数:
Calendar cal = Calendar.getInstance();
int day=cal.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(day);


2.java.util.Date

java.util.Date today=new java.util.Date();
System.out.println("Today is "+formats.format(today));

取当月的第一天:
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-01");
java.util.Date firstDay=new java.util.Date();
System.out.println("the month first day is "+formats.format(firstDay));
取当月的最后一天:
Calendar cal = Calendar.getInstance();
int maxDay=cals.getActualMaximum(Calendar.DAY_OF_MONTH);
java.text.Format formatter3=new java.text.SimpleDateFormat("yyyy-MM-"+maxDay);
System.out.println(formatter3.format(cal.getTime()));

求两个日期之间相隔的天数:
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date beginDate= format.parse("2007-12-24");
java.util.Date endDate= format.parse("2007-12-25");
long day=(date.getTime()-mydate.getTime())/(24*60*60*1000);
System.out.println("相隔的天数="+day);
一年前的日期:
java.text.Format formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date todayDate=new java.util.Date();
long beforeTime=(todayDate.getTime()/1000)-60*60*24*365;
todayDate.setTime(beforeTime*1000);
String beforeDate=formatter.format(todayDate);
System.out.println(beforeDate);
一年后的日期:
java.text.Format formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date todayDate=new java.util.Date();
long afterTime=(todayDate.getTime()/1000)+60*60*24*365;
todayDate.setTime(afterTime*1000);
String afterDate=formatter.format(todayDate);
System.out.println(afterDate);

求10小时后的时间
java.util.Calendar Cal=java.util.Calendar.getInstance();
Cal.setTime(dateOper);
Cal.add(java.util.Calendar.HOUR_OF_DAY,10);
System.out.println("date:"+forma.format(Cal.getTime()));

求10小时前的时间

java.util.Calendar Cal=java.util.Calendar.getInstance();
Cal.setTime(dateOper);
Cal.add(java.util.Calendar.HOUR_OF_DAY,-10);
System.out.println("date:"+forma.format(Cal.getTime()));

3.java.sql.Date
继承自java.util.Date,是操作数据库用的日期类型
java.sql.Date sqlDate = new java.sql.Date(java.sql.Date.valueOf("2007-12-25").getTime());
日期比较:简单的比较可以以字符串的形式直接比较,也可使用
java.sql.Date.valueOf("2007-03-08").compareTo(java.sql.Date.valueOf("2007-03-18"))方式来比较日期的大小.也可使用java.util.Date.after(java.util.Date)来比较.

相差时间:
long difference=c2.getTimeInMillis()-c1.getTimeInMillis();
相差天数:long day=difference/(3600*24*1000)
相差小时:long hour=difference/(3600*1000)
相差分钟:long minute=difference/(60*1000)
相差秒: long second=difference/1000

补充:
DateFormat df=new SimpleDateFormat("yyyy-MM-dd EE hh:mm:ss");
System.out.println(df.format(new Date()));
Date date = new Date();
DateFormat shortDate=DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
DateFormat mediumDate =DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
DateFormat longDate =DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
DateFormat fullDate =DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

system.out.println(shortDate.format(date));
System.out.println(mediumDate.format(date));
System.out.println(longDate.format(date));
System.out.println(fullDate.format(date));

08-4-15 下午3:24
2008-4-15 15:24:31
2008年4月15日 下午03时24分31秒
2008年4月15日 星期二 下午03时24分31秒CST


Calendar c = Calendar.getInstance();

c.add(Calendar.MONTH, 1); // 目前时间加1个月
System.out.println(df.format(c.getTime()));

c.add(Calendar.HOUR, 3); // 目前时间加3小时
System.out.println(df.format(c.getTime()));

c.add(Calendar.YEAR, -2); // 目前时间减2年
System.out.println(df.format(c.getTime()));

c.add(Calendar.DAY_OF_WEEK, 7); // 目前的时间加7天
System.out.println(df.format(c.getTime())); 


JAVA图片水印、缩放 java JAVA图片水印、缩放
package com.hmw.picMark;
 
 import java.awt.AlphaComposite;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.geom.AffineTransform;
 import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 
 import javax.imageio.ImageIO;
 
 /**
  * 图片工具类, 图片水印,文字水印,缩放,补白等
  * @author Carl He
  */
 public final class ImageUtils {
     /**图片格式:JPG*/
     private static final String PICTRUE_FORMATE_JPG = "jpg";
     
     private ImageUtils(){}
     /**
      * 添加图片水印
      * @param targetImg 目标图片路径,如:C://myPictrue//1.jpg
      * @param waterImg  水印图片路径,如:C://myPictrue//logo.png
      * @param x 水印图片距离目标图片左侧的偏移量,如果x<0, 则在正中间
      * @param y 水印图片距离目标图片上侧的偏移量,如果y<0, 则在正中间
      * @param alpha 透明度(0.0 -- 1.0, 0.0为完全透明,1.0为完全不透明)
 */
     public final static void pressImage(String targetImg, String waterImg, int x, int y, float alpha) {
             try {
                 File file = new File(targetImg);
                 Image image = ImageIO.read(file);
                 int width = image.getWidth(null);
                 int height = image.getHeight(null);
                 BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                 Graphics2D g = bufferedImage.createGraphics();
                 g.drawImage(image, 0, 0, width, height, null);
             
                 Image waterImage = ImageIO.read(new File(waterImg));    // 水印文件
                 int width_1 = waterImage.getWidth(null);
                 int height_1 = waterImage.getHeight(null);
                 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
                 
                 int widthDiff = width - width_1;
                 int heightDiff = height - height_1;
                 if(x < 0){
                     x = widthDiff / 2;
                 }else if(x > widthDiff){
                     x = widthDiff;
                 }
                 if(y < 0){
                     y = heightDiff / 2;
                 }else if(y > heightDiff){
                     y = heightDiff;
                 }
                 g.drawImage(waterImage, x, y, width_1, height_1, null); // 水印文件结束
                 g.dispose();
                 ImageIO.write(bufferedImage, PICTRUE_FORMATE_JPG, file);
             } catch (IOException e) {
                 e.printStackTrace();
             }
     }
 
     /**
      * 添加文字水印
      * @param targetImg 目标图片路径,如:C://myPictrue//1.jpg
      * @param pressText 水印文字, 如:中国证券网
      * @param fontName 字体名称,    如:宋体
      * @param fontStyle 字体样式,如:粗体和斜体(Font.BOLD|Font.ITALIC)
      * @param fontSize 字体大小,单位为像素
      * @param color 字体颜色
      * @param x 水印文字距离目标图片左侧的偏移量,如果x<0, 则在正中间
      * @param y 水印文字距离目标图片上侧的偏移量,如果y<0, 则在正中间
      * @param alpha 透明度(0.0 -- 1.0, 0.0为完全透明,1.0为完全不透明)
 */
     public static void pressText(String targetImg, String pressText, String fontName, int fontStyle, int fontSize, Color color, int x, int y, float alpha) {
         try {
             File file = new File(targetImg);
             
             Image image = ImageIO.read(file);
             int width = image.getWidth(null);
             int height = image.getHeight(null);
             BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
             Graphics2D g = bufferedImage.createGraphics();
             g.drawImage(image, 0, 0, width, height, null);
             g.setFont(new Font(fontName, fontStyle, fontSize));
             g.setColor(color);
             g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
             
             int width_1 = fontSize * getLength(pressText);
             int height_1 = fontSize;
             int widthDiff = width - width_1;
             int heightDiff = height - height_1;
             if(x < 0){
                 x = widthDiff / 2;
             }else if(x > widthDiff){
                 x = widthDiff;
             }
             if(y < 0){
                 y = heightDiff / 2;
             }else if(y > heightDiff){
                 y = heightDiff;
             }
             
             g.drawString(pressText, x, y + height_1);
             g.dispose();
             ImageIO.write(bufferedImage, PICTRUE_FORMATE_JPG, file);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
     
     /**
      * 获取字符长度,一个汉字作为 1 个字符, 一个英文字母作为 0.5 个字符
      * @param text
      * @return 字符长度,如:text="中国",返回 2;text="test",返回 2;text="中国ABC",返回 4.
 */
     public static int getLength(String text) {
         int textLength = text.length();
         int length = textLength;
         for (int i = 0; i < textLength; i++) {
             if (String.valueOf(text.charAt(i)).getBytes().length > 1) {
                 length++;
             }
         }
         return (length % 2 == 0) ? length / 2 : length / 2 + 1;
     }
 
     /**
      * 图片缩放
      * @param filePath 图片路径
      * @param height 高度
      * @param width 宽度
      * @param bb 比例不对时是否需要补白
 */
     public static void resize(String filePath, int height, int width, boolean bb) {
         try {
             double ratio = 0; //缩放比例    
             File f = new File(filePath);   
             BufferedImage bi = ImageIO.read(f);   
             Image itemp = bi.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH);   
             //计算比例   
             if ((bi.getHeight() > height) || (bi.getWidth() > width)) {   
                 if (bi.getHeight() > bi.getWidth()) {   
                     ratio = (new Integer(height)).doubleValue() / bi.getHeight();   
                 } else {   
                     ratio = (new Integer(width)).doubleValue() / bi.getWidth();   
                 }   
                 AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);   
                 itemp = op.filter(bi, null);   
             }   
             if (bb) {   
                 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);   
                 Graphics2D g = image.createGraphics();   
                 g.setColor(Color.white);   
                 g.fillRect(0, 0, width, height);   
                 if (width == itemp.getWidth(null))   
                     g.drawImage(itemp, 0, (height - itemp.getHeight(null)) / 2, itemp.getWidth(null), itemp.getHeight(null), Color.white, null);   
                 else  
                     g.drawImage(itemp, (width - itemp.getWidth(null)) / 2, 0, itemp.getWidth(null), itemp.getHeight(null), Color.white, null);   
                 g.dispose();   
                 itemp = image;   
             }
             ImageIO.write((BufferedImage) itemp, "jpg", f);   
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
 
     public static void main(String[] args) throws IOException {
         pressImage("C://pic//jpg", "C://pic//test.gif", 5000, 5000, 0f);
         pressText("C://pic//jpg", "旺仔之印", "宋体", Font.BOLD|Font.ITALIC, 20, Color.BLACK, 0, 0, 8f);
         resize("C://pic//4.jpg", 1000, 500, true);
     }
 }
dom4j解析xml dom4j, xml dom4j解析XML文件
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


public class Dom4jReaderXML {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws DocumentException {
		SAXReader saxReader = new SAXReader();
		//1.读取xml文件
		Document doc = saxReader.read(Dom4jReaderXML.class.getClassLoader().getResourceAsStream("struts.xml"));
		//还可以通过下面方法读取
		//Document doc = saxReader.read("src/struts.xml");
		//以下两种方式是通过绝对路径读取xml文件
		//String path = "D:/MyEclipse 8.6/spring/springmvc/src/struts.xml";
		//Document doc = saxReader.read(path);
		//Document doc = saxReader.read(new File(path));
		Element root = doc.getRootElement();//获取根元素struts
		Element element = root.element("package");//获取元素package
		//System.out.println(element.asXML());//获取package节点的内容
		System.out.println("package name=" + element.attributeValue("name"));
		//遍历元素package下所有的action元素
		for(Element action_element : (List<Element>)element.elements("action")) {
			//获取元素action的属性
			System.out.print("  action name=" + action_element.attributeValue("name"));
			System.out.print(" class=" + action_element.attributeValue("class"));
			System.out.println(" method=" + action_element.attributeValue("method"));
			//遍历元素action下所有的result元素
			for(Element rusult_element : (List<Element>)action_element.elements("result")) {
				//获取元素result的属性
				System.out.print("    result name=" + rusult_element.attributeValue("name"));
				if(rusult_element.isTextOnly()) {
					System.out.println(" value=" + rusult_element.getText());
				} else {
					System.out.println();
					//遍历元素result下所有的param元素
					for(Element param_elment : (List<Element>)rusult_element.elements("param")) {
						//获取元素param的属性
						System.out.print("      param name=" + param_elment.attributeValue("name"));
						System.out.println(" value=" + param_elment.getText());
					}
				}
			}
		}
	}
}
数字金额转换为中文大写金额 java 数字金额转换为中文大写金额
//yuyong 5-23
		var chineseMoney="";
					var numMoney="01.23";
					var chinese_number=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"];
					var chinese_zheng_qian1=["","万","亿"];
					var chinese_zheng_qian2=["","拾","佰","仟"];
					var chinese_ling_qian=["角","分"];
					var money_Reg=/^\d{1,12}(\.\d{1,2})?$/;
					if(!money_Reg.test(numMoney)){
						alert("数字格式不对!"); 
					}else{
						var zheng_qian=Number(numMoney.split("\.")[0])+"";
						var ling_qian=numMoney.split("\.")[1];
						var length=parseInt(zheng_qian.length/4)+(zheng_qian.length%4!=0?1:0);
						for(var x=1;x<=length;x++){ 
							var start=(x-1)*4+1;
							var temp="";
							for(var y=0;y<=3;y++){  //每四位一组中从低到高 单位为  ""->拾->佰->仟
										var a=zheng_qian.charAt(zheng_qian.length-start);
										if(a=='0'){
											if(temp!=""){ //4位一组中两个连续的零 ,中文中只读一个零
												if(zheng_qian.charAt(zheng_qian.length-start+1)!='0')
													temp=chinese_number[a]+temp;
											}
										}else
											temp=chinese_number[a]+chinese_zheng_qian2[y]+temp;
										if(start==zheng_qian.length)
											break;
										else
											start++;						
							}
							if(temp!='')
									chineseMoney=temp+chinese_zheng_qian1[x-1]+chineseMoney;
						}
						if(chineseMoney=="")
							chineseMoney=chinese_number[0];
						if(ling_qian!=undefined&&ling_qian!='00'){
							chineseMoney+="圆";
							for(a=0;a<=ling_qian.length-1;a++){
								if(ling_qian.charAt(a)!='0')
									chineseMoney+=chinese_number[ling_qian.charAt(a)]+chinese_ling_qian[a];
							}
						}else{
							chineseMoney+="圆整";
						}
						alert(chineseMoney);
					}

j2ee常用工具类_文件打包解包处理类 java J2EE常用工具类—文件打包解包处理类
package cn.org.jshuwei.j2ee.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream;

/**
* 文件压缩解压工具类
* 
* @author huwei(jshuwei.org.cn)
* @since 1.2
* 
*/
public class ZipUtil {
    /**
     * 压缩ZIP文件,将baseDirName目录下的所有文件压缩到targetFileName.ZIP文件中
     * 
     * @param baseDirName
     *            需要压缩的文件的跟目录
     * @param targetFileName
     *            压缩有生成的文件名
     */
    public static void zipFile(String baseDirName, String targetFileName) {
        if (baseDirName == null) {
            return;
        }
        File file = new File(baseDirName);
        if (!file.exists()) {
            return;
        }
        String baseDirPath = file.getAbsolutePath();
        File targetFile = new File(targetFileName);
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
                    targetFile));
            if (file.isFile()) {
                fileToZip(baseDirPath, file, out);
            } else {
                dirToZip(baseDirPath, file, out);
            }
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 解压缩ZIP文件,将ZIP文件里的内容解压到targetBaseDirName目录下
     * 
     * @param zipFileName
     *            待解压缩的ZIP文件名
     * @param targetBaseDirName
     *            目标目录
     */
    @SuppressWarnings("unchecked")
    public static void unzipFile(String zipFileName, String targetBaseDirName) {
        if (!targetBaseDirName.endsWith(File.separator)) {
            targetBaseDirName += File.separator;
        }
        try {
            ZipFile zipFile = new ZipFile(zipFileName);
            ZipEntry entry = null;
            String entryName = null;
            String targetFileName = null;
            byte[] buffer = new byte[4096];
            int bytes_read;
            Enumeration entrys = zipFile.getEntries();//.entries();
            while (entrys.hasMoreElements()) {
                entry = (ZipEntry) entrys.nextElement();
                entryName = entry.getName();
                targetFileName = targetBaseDirName + entryName;
                if (entry.isDirectory()) {
                    new File(targetFileName).mkdirs();
                    continue;
                } else {
                    new File(targetFileName).getParentFile().mkdirs();
                }
                File targetFile = new File(targetFileName);
                FileOutputStream os = new FileOutputStream(targetFile);
                InputStream is = zipFile.getInputStream(entry);
                while ((bytes_read = is.read(buffer)) != -1) {
                    os.write(buffer, 0, bytes_read);
                }
                os.close();
                is.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void dirToZip(String baseDirPath, File dir,
            ZipOutputStream out) {
        if (dir.isDirectory()) {
            File[] files = dir.listFiles();
            if (files.length == 0) {
                ZipEntry entry = new ZipEntry(getEntryName(baseDirPath, dir));
                try {
                    out.putNextEntry(entry);
                    out.closeEntry();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return;
            }
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    fileToZip(baseDirPath, files[i], out);
                } else {
                    dirToZip(baseDirPath, files[i], out);
                }
            }
        }
    }

    private static void fileToZip(String baseDirPath, File file,
            ZipOutputStream out) {
        FileInputStream in = null;
        ZipEntry entry = null;
        byte[] buffer = new byte[4096];
        int bytes_read;
        if (file.isFile()) {
            try {
                in = new FileInputStream(file);
                entry = new ZipEntry(getEntryName(baseDirPath, file));
                out.putNextEntry(entry);
                while ((bytes_read = in.read(buffer)) != -1) {
                    out.write(buffer, 0, bytes_read);
                }
                out.closeEntry();
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static String getEntryName(String baseDirPath, File file) {
        if (!baseDirPath.endsWith(File.separator)) {
            baseDirPath += File.separator;
        }
        String filePath = file.getAbsolutePath();
        if (file.isDirectory()) {
            filePath += "/";
        }
        int index = filePath.indexOf(baseDirPath);
        return filePath.substring(index + baseDirPath.length());
    }
}
j2ee常用工具类_文件操作工具类 java J2EE常用工具类——文件操作类
package cn.org.jshuwei.j2ee.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件操作工具类
 * 
 * @author huwei(jshuwei.org.cn)
 * @since 1.2
 * 
 */
public class FileUtil {
	/**
	 * 将字节流转换成字符串返回
	 * 
	 * @param is
	 *            输入流
	 * @return 字符串
	 */
	public static String readFileByLines(InputStream is) {
		BufferedReader reader = null;
		StringBuffer sb = new StringBuffer();
		try {
			reader = new BufferedReader(new InputStreamReader(is));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				sb.append(tempString + "\n");
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return sb.toString();
	}

	/**
	 * 将文件一行一行的读成List返回
	 * 
	 * @param file
	 *            需要读取的文件
	 * @return 文件的一行就是一个List的Item的返回
	 */
	public static List<String> readFileToList(File file) {
		BufferedReader reader = null;
		List<String> list = new ArrayList<String>();
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				list.add(tempString);
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return list;
	}

	/**
	 * 将文件按照一定的编码方式一行一行的读成List返回
	 * 
	 * @param file
	 *            需要读取的文件
	 * @param encodType
	 *            字符编码
	 * @return 文件的一行就是一个List的Item的返回
	 */
	public static List<String> readFileToList(File file, String encodType) {
		BufferedReader reader = null;
		List<String> list = new ArrayList<String>();
		try {
			reader = new BufferedReader(new InputStreamReader(
					new FileInputStream(file), encodType));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				if (!(tempString.charAt(0) >= 'a' && tempString.charAt(0) <= 'z'))
					tempString = tempString.substring(1);
				list.add(tempString);
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return list;
	}

	/**
	 * 将指定的字符串内容以指定的方式写入到指定的文件中
	 * 
	 * @param file
	 *            需要写人的文件
	 * @param content
	 *            需要写入的内容
	 * @param flag
	 *            是否追加写入
	 */
	public static void writeFile(File file, String content, Boolean flag) {
		try {
			if (!file.exists())
				file.createNewFile();
			FileWriter writer = new FileWriter(file, flag);
			writer.write(content);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 将指定的字符串内容以指定的方式及编码写入到指定的文件中
	 * 
	 * @param file
	 *            需要写人的文件
	 * @param content
	 *            需要写入的内容
	 * @param flag
	 *            是否追加写入
	 * @param encodType
	 *            文件编码
	 */
	public static void writeFile(File file, String content, Boolean flag,
			String encodType) {
		try {
			FileOutputStream writerStream = new FileOutputStream(file, flag);
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
					writerStream, encodType));
			writer.write(content);
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 拷贝文件夹
	 * 
	 * @param oldPath
	 *            源目录
	 * @param newPath
	 *            目标目录
	 */
	public static void copyFolder(String oldPath, String newPath) {
		try {
			(new File(newPath)).mkdirs();
			File a = new File(oldPath);
			String[] file = a.list();
			File temp = null;
			for (int i = 0; i < file.length; i++) {
				if (oldPath.endsWith(File.separator)) {
					temp = new File(oldPath + file[i]);
				} else {
					temp = new File(oldPath + File.separator + file[i]);
				}
				if (temp.isFile()) {
					FileInputStream input = new FileInputStream(temp);
					FileOutputStream output = new FileOutputStream(newPath
							+ "/" + (temp.getName()).toString());
					byte[] b = new byte[1024 * 5];
					int len;
					while ((len = input.read(b)) != -1) {
						output.write(b, 0, len);
					}
					output.flush();
					output.close();
					input.close();
				}
				if (temp.isDirectory()) {
					copyFolder(oldPath + "/" + file[i], newPath + "/" + file[i]);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 将文件重命名
	 * 
	 * @param oldName
	 *            源文件名
	 * @param newName
	 *            新文件名
	 */
	public static void reName(String oldName, String newName) {
		File oldF = new File(oldName);
		File newF = new File(newName);
		oldF.renameTo(newF);
	}

	/**
	 * 将一个文件列表文件中所有文件拷贝到指定目录中
	 * 
	 * @param listFile
	 *            包含需要拷贝的文件的列表的文件,每个文件写在一行
	 * @param targetFloder
	 *            目标目录
	 */
	public static void copyFilesFromList(String listFile, String targetFloder) {
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(listFile));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				copyFile(tempString, targetFloder);
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	/**
	 * 拷贝文件
	 * 
	 * @param oldPath
	 *            源文件
	 * @param newPath
	 *            目标文件
	 */
	public static void copyFile(String oldPath, String newPath) {
		try {
			File temp = new File(oldPath);
			FileInputStream input = new FileInputStream(temp);
			FileOutputStream output = new FileOutputStream(newPath + "/"
					+ (temp.getName()).toString());
			byte[] b = new byte[1024 * 5];
			int len;
			while ((len = input.read(b)) != -1) {
				output.write(b, 0, len);
			}
			output.flush();
			output.close();
			input.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除文件列表
	 * 
	 * @param files
	 *            需要删除的文件/文件夹列表
	 * @return 删除成功true,否则返回false
	 */
	public static boolean deleteFiles(List<String> files) {
		boolean flag = true;
		for (String file : files) {
			flag = delete(file);
			if (!flag)
				break;
		}
		return flag;
	}

	/**
	 * 删除文件或文件夹
	 * 
	 * @param fileName
	 *            要删除的文件名
	 * @return 删除成功返回true,否则返回false
	 */
	public static boolean delete(String fileName) {
		File file = new File(fileName);
		if (!file.exists()) {
			return false;
		} else {
			if (file.isFile())
				return deleteFile(fileName);
			else
				return deleteDirectory(fileName);
		}
	}

	/**
	 * 删除文件
	 * 
	 * @param fileName
	 *            要删除的文件的文件名
	 * @return 删除成功返回true,否则返回false
	 */
	public static boolean deleteFile(String fileName) {
		File file = new File(fileName);
		if (file.exists() && file.isFile())
			return file.delete();
		return false;
	}

	/**
	 * 删除目录及目录下的文件
	 * 
	 * @param dir
	 *            要删除的目录路径
	 * @return 删除成功返回true,否则返回false
	 */
	public static boolean deleteDirectory(String dir) {
		if (!dir.endsWith(File.separator))
			dir = dir + File.separator;
		File dirFile = new File(dir);
		if ((!dirFile.exists()) || (!dirFile.isDirectory()))
			return false;
		boolean flag = true;
		File[] files = dirFile.listFiles();
		for (int i = 0; i < files.length; i++) {
			if (files[i].isFile()) {
				flag = deleteFile(files[i].getAbsolutePath());
				if (!flag)
					break;
			} else if (files[i].isDirectory()) {
				flag = deleteDirectory(files[i].getAbsolutePath());
				if (!flag)
					break;
			}
		}
		if (!flag) {
			return false;
		}
		return dirFile.delete();
	}
}
j2ee常用工具_json工具类 java J2EE常用工具类——Json工具类
package cn.org.jshuwei.j2ee.util;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
* Json工具类,实现了实体类和Json数据格式之间的互转功能 使用实例:<br>
* 
* <pre>
* User类:
* package cn.org.jshuwei.j2ee.util.test;
* 
* public class User {
*     private String userName;
*     private String userPass;
*     private Integer userAge;
*     
*     public User(){
*         
*     }
*     
*     public User(String userName, String userPass, int userAge) {
*         super();
*         this.userName = userName;
*         this.userPass = userPass;
*         this.userAge = userAge;
*     }
*     
*     public String getUserName() {
*         return userName;
*     }
*     public void setUserName(String userName) {
*         this.userName = userName;
*     }
*     public String getUserPass() {
*         return userPass;
*     }
*     public void setUserPass(String userPass) {
*         this.userPass = userPass;
*     }
*     public Integer getUserAge() {
*         return userAge;
*     }
*     public void setUserAge(Integer userAge) {
*         this.userAge = userAge;
*     }
* 
*     @Override
*     public String toString() {
*         return "name->"+this.userName+";pass->"+this.userPass+";age->"+this.userAge;
*     }
* }
* 
* 测试调用类:
* package cn.org.jshuwei.j2ee.util.test;
* 
* import cn.org.jshuwei.j2ee.util.JsonUtils;
* 
* public class Test {
* 
*     public static void main(String[] args) {
*         String str1 = "{userName:'huwei', userAge:23, userPass:'123'}";
*         String str2 = "[{'userAge':23,'userName':'huwei','userPass':'123'},{'userAge':32,'userName':'jshuwei','userPass':'pass'},{'userAge':'','userName':'userName','userPass':''}]";
*         User u = (User)JsonUtils.json2Object(str1, User.class);
*         System.out.println("u-->"+u);
*         Object[] objs = JsonUtils.json2ObjectArray(str2);
*         for(Object obj : objs){
*             User u1 = (User)JsonUtils.json2Object(obj.toString(), User.class);
*             System.out.println(u1);
*         }
*     }    
* }
* 
* </pre>
* 
* @author huwei(jshuwei.org.cn)
* 
*/
public class JsonUtils {
    /**
     * 将一个实体类对象转换成Json数据格式
     * 
     * @param bean
     *            需要转换的实体类对象
     * @return 转换后的Json格式字符串
     */
    public static String beanToJson(Object bean) {
        StringBuilder json = new StringBuilder();
        json.append("{");
        PropertyDescriptor[] props = null;
        try {
            props = Introspector.getBeanInfo(bean.getClass(), Object.class)
                    .getPropertyDescriptors();
        } catch (IntrospectionException e) {
        }
        if (props != null) {
            for (int i = 0; i < props.length; i++) {
                try {
                    String name = objectToJson(props[i].getName());
                    String value = objectToJson(props[i].getReadMethod()
                            .invoke(bean));
                    json.append(name);
                    json.append(":");
                    json.append(value);
                    json.append(",");
                } catch (Exception e) {
                }
            }
            json.setCharAt(json.length() - 1, '}');
        } else {
            json.append("}");
        }
        return json.toString();
    }

    /**
     * 将一个List对象转换成Json数据格式返回
     * 
     * @param list
     *            需要进行转换的List对象
     * @return 转换后的Json数据格式字符串
     */
    public static String listToJson(List<?> list) {
        StringBuilder json = new StringBuilder();
        json.append("[");
        if (list != null && list.size() > 0) {
            for (Object obj : list) {
                json.append(objectToJson(obj));
                json.append(",");
            }
            json.setCharAt(json.length() - 1, ']');
        } else {
            json.append("]");
        }
        return json.toString();
    }

    /**
     * 将一个对象数组转换成Json数据格式返回
     * 
     * @param array
     *            需要进行转换的数组对象
     * @return 转换后的Json数据格式字符串
     */
    public static String arrayToJson(Object[] array) {
        StringBuilder json = new StringBuilder();
        json.append("[");
        if (array != null && array.length > 0) {
            for (Object obj : array) {
                json.append(objectToJson(obj));
                json.append(",");
            }
            json.setCharAt(json.length() - 1, ']');
        } else {
            json.append("]");
        }
        return json.toString();
    }

    /**
     * 将一个Map对象转换成Json数据格式返回
     * 
     * @param map
     *            需要进行转换的Map对象
     * @return 转换后的Json数据格式字符串
     */
    public static String mapToJson(Map<?, ?> map) {
        StringBuilder json = new StringBuilder();
        json.append("{");
        if (map != null && map.size() > 0) {
            for (Object key : map.keySet()) {
                json.append(objectToJson(key));
                json.append(":");
                json.append(objectToJson(map.get(key)));
                json.append(",");
            }
            json.setCharAt(json.length() - 1, '}');
        } else {
            json.append("}");
        }
        return json.toString();
    }

    /**
     * 将一个Set对象转换成Json数据格式返回
     * 
     * @param set
     *            需要进行转换的Set对象
     * @return 转换后的Json数据格式字符串
     */
    public static String setToJson(Set<?> set) {
        StringBuilder json = new StringBuilder();
        json.append("[");
        if (set != null && set.size() > 0) {
            for (Object obj : set) {
                json.append(objectToJson(obj));
                json.append(",");
            }
            json.setCharAt(json.length() - 1, ']');
        } else {
            json.append("]");
        }
        return json.toString();
    }

    private static String numberToJson(Number number) {
        return number.toString();
    }

    private static String booleanToJson(Boolean bool) {
        return bool.toString();
    }

    private static String nullToJson() {
        return "";
    }

    private static String stringToJson(String s) {
        if (s == null) {
            return nullToJson();
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            switch (ch) {
            case '"':
                sb.append("\\\"");
                break;
            case '\\':
                sb.append("\\\\");
                break;
            case '\b':
                sb.append("\\b");
                break;
            case '\f':
                sb.append("\\f");
                break;
            case '\n':
                sb.append("\\n");
                break;
            case '\r':
                sb.append("\\r");
                break;
            case '\t':
                sb.append("\\t");
                break;
            case '/':
                sb.append("\\/");
                break;
            default:
                if (ch >= '\u0000' && ch <= '\u001F') {
                    String ss = Integer.toHexString(ch);
                    sb.append("\\u");
                    for (int k = 0; k < 4 - ss.length(); k++) {
                        sb.append('0');
                    }
                    sb.append(ss.toUpperCase());
                } else {
                    sb.append(ch);
                }
            }
        }
        return sb.toString();
    }

    private static String objectToJson(Object obj) {
        StringBuilder json = new StringBuilder();
        if (obj == null) {
            json.append("\"\"");
        } else if (obj instanceof Number) {
            json.append(numberToJson((Number) obj));
        } else if (obj instanceof Boolean) {
            json.append(booleanToJson((Boolean) obj));
        } else if (obj instanceof String) {
            json.append("\"").append(stringToJson(obj.toString())).append("\"");
        } else if (obj instanceof Object[]) {
            json.append(arrayToJson((Object[]) obj));
        } else if (obj instanceof List) {
            json.append(listToJson((List<?>) obj));
        } else if (obj instanceof Map) {
            json.append(mapToJson((Map<?, ?>) obj));
        } else if (obj instanceof Set) {
            json.append(setToJson((Set<?>) obj));
        } else {
            json.append(beanToJson(obj));
        }
        return json.toString();
    }

    // ============================================================================================

    /**
     * 将Json格式的字符串转换成指定的对象返回
     * 
     * @param jsonString
     *            Json格式的字符串
     * @param pojoCalss
     *            转换后的对象类型
     * @return 转换后的对象
     */
    @SuppressWarnings("unchecked")
    public static Object json2Object(String jsonString, Class pojoCalss) {
        Object pojo;
        JSONObject jsonObject = JSONObject.fromObject(jsonString);
        pojo = JSONObject.toBean(jsonObject, pojoCalss);
        return pojo;
    }

    /**
     * 将Json格式的字符串转换成Map<String,Object>对象返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的Map<String,Object>对象
     */
    @SuppressWarnings("unchecked")
    public static Map<String, Object> json2Map(String jsonString) {
        JSONObject jsonObject = JSONObject.fromObject(jsonString);
        Iterator keyIter = jsonObject.keys();
        String key;
        Object value;
        Map<String, Object> valueMap = new HashMap<String, Object>();
        while (keyIter.hasNext()) {
            key = (String) keyIter.next();
            value = jsonObject.get(key);
            valueMap.put(key, value);
        }
        return valueMap;
    }

    /**
     * 将Json格式的字符串转换成对象数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的对象数组
     */
    public static Object[] json2ObjectArray(String jsonString) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        return jsonArray.toArray();
    }

    /**
     * 将Json格式的字符串转换成指定对象组成的List返回
     * 
     * @param jsonString
     *            Json格式的字符串
     * @param pojoClass
     *            转换后的List中对象类型
     * @return 转换后的List对象
     */
    @SuppressWarnings("unchecked")
    public static List json2List(String jsonString, Class pojoClass) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        JSONObject jsonObject;
        Object pojoValue;
        List list = new ArrayList();
        for (int i = 0; i < jsonArray.size(); i++) {
            jsonObject = jsonArray.getJSONObject(i);
            pojoValue = JSONObject.toBean(jsonObject, pojoClass);
            list.add(pojoValue);
        }
        return list;
    }

    /**
     * 将Json格式的字符串转换成字符串数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的字符串数组
     */
    public static String[] json2StringArray(String jsonString) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        String[] stringArray = new String[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            stringArray[i] = jsonArray.getString(i);
        }
        return stringArray;
    }

    /**
     * 将Json格式的字符串转换成Long数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的Long数组
     */
    public static Long[] json2LongArray(String jsonString) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        Long[] longArray = new Long[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            longArray[i] = jsonArray.getLong(i);
        }
        return longArray;
    }

    /**
     * 将Json格式的字符串转换成Integer数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的Integer数组
     */
    public static Integer[] json2IntegerArray(String jsonString) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        Integer[] integerArray = new Integer[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            integerArray[i] = jsonArray.getInt(i);
        }
        return integerArray;
    }

    /**
     * 将Json格式的字符串转换成日期数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @param DataFormat
     *            返回的日期格式
     * @return 转换后的日期数组
     */
    public static Date[] json2DateArray(String jsonString, String DataFormat) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        Date[] dateArray = new Date[jsonArray.size()];
        String dateString;
        Date date;
        for (int i = 0; i < jsonArray.size(); i++) {
            dateString = jsonArray.getString(i);
            date = DateUtil.parseDate(dateString, DataFormat);
            dateArray[i] = date;

        }
        return dateArray;
    }

    /**
     * 将Json格式的字符串转换成Double数组返回
     * 
     * @param jsonString
     *            需要进行转换的Json格式字符串
     * @return 转换后的Double数组
     */
    public static Double[] json2DoubleArray(String jsonString) {
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        Double[] doubleArray = new Double[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            doubleArray[i] = jsonArray.getDouble(i);
        }
        return doubleArray;
    }
}
j2ee常用工具类_时间处理工具类 java J2EE常用工具类—时间处理工具类
package cn.org.jshuwei.j2ee.util;

import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
* 
* 日期操作的工具类
* 
* @author huwei(jshuwei.org.cn)
* @since 1.0
* 
*/
public class DateUtil {

    private static String defDtPtn = "yyyy-MM-dd HH:mm:ss";// 缺省日期格式

    /**
     * 计算给定时间至今的天数
     * 
     * @since 1.1
     * @param date
     *            给定的时间
     * @return 给定时间至今的天数
     */
    public static long date2day(String date) {
        long day = 0;
        DateFormat df = DateFormat.getDateInstance();
        try {
            long old = df.parse(date).getTime();
            long now = new java.util.Date().getTime();
            long secs = now - old;
            day = secs / (1000 * 24 * 60 * 60);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }

    /**
     * 格式化给定时间后day天的时间
     * 
     * @since 1.0
     * @param date
     *            需要格式化的时间
     * @param day
     *            增加的天数
     * @return 给定时间的后day天的格式化字符串(如:2008-11-22)
     */
    public static String formatDate(java.util.Date date, Integer day) {
        String str = "";
        str = new Date(date.getTime() + day * 24 * 60 * 60).toString();
        return str;
    }

    /**
     * 格式化给定时间
     * 
     * @param date
     *            需要格式化的时间
     * @return 给定时间的格式化字符串(如:2008-11-22)
     */
    public static String formatDate(java.util.Date date) {
        return new Date(date.getTime()).toString();
    }

    /**
     * 得到当前年
     * 
     * @since 1.0
     * @return 返回当前年(YYYY)
     */
    public static int getYear() {
        return Calendar.getInstance().get(Calendar.YEAR);
    }

    /**
     * 得到当前月
     * 
     * @since 1.0
     * @return 返回当前月(1~12)
     */
    public static int getMonth() {
        return Calendar.getInstance().get(Calendar.MONTH) + 1;
    }

    /**
     * 得到当前日
     * 
     * @since 1.0
     * @return 返回当前日(1~31)
     */
    public static int getDay() {
        return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 得到当前年
     * 
     * @since 1.0
     * @return 返回当前年(YY)
     */
    public static String getYear2() {
        int year = getYear();
        return StringUtil.Integer2String(year, "1986").substring(2, 4);
    }

    /**
     * 得到当前月
     * 
     * @since 1.0
     * @return 返回当前月(01~12)
     */
    public static String getMonth2() {
        int month = getMonth();
        if (month < 10) {
            return "0" + StringUtil.Integer2String(month, "00");
        }
        return StringUtil.Integer2String(month, "00");
    }

    /**
     * 得到当前日
     * 
     * @since 1.0
     * @return 返回当前日(01~31)
     */
    public static String getDay2() {
        int day = getDay();
        if (day < 10) {
            return "0" + StringUtil.Integer2String(day, "00");
        }
        return StringUtil.Integer2String(day, "00");
    }

    /**
     * 得到指定格式的当前时间
     * 
     * @param format
     *            格式化形式(年用YY/YYYY表示;月用M/MM表示;日用D/DD表示,之间任意任序组合),<br />
     *            如"YYYY-MM-DD"返回形如:1986-12-17<br />
     *            如"YY-MM"返回形如:86-12<br />
     *            如"YY年MM月"返回形如:86年12月……
     * @since 1.0
     * @return 返回指定格式的当前时间
     * 
     */
    public static String getDate(String format) {
        format = format.replace("YYYY", getYear() + "");
        format = format.replace("YY", getYear2());
        format = format.replace("MM", getMonth2());
        format = format.replace("M", getMonth() + "");
        format = format.replace("DD", getDay2());
        format = format.replace("D", getDay() + "");
        return format;
    }

    /**
     * 将字符串按指定格式解析成日期对象
     * 
     * @since 1.1
     * @param dateStr
     *            需要进行转换的日期字符串
     * @param pattern
     *            日期字符串的格式
     * @return "yyyy-MM-dd HH:mm:ss"形式的日期对象
     */
    public static java.util.Date parseDate(String dateStr, String pattern) {
        SimpleDateFormat DATEFORMAT = new SimpleDateFormat(defDtPtn);
        DATEFORMAT.applyPattern(pattern);
        java.util.Date ret = null;
        try {
            ret = DATEFORMAT.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        DATEFORMAT.applyPattern(defDtPtn);
        return ret;
    }

    /**
     * 计算详细年龄
     * 
     * @since 1.1
     * @param birthdayStr
     *            出生日期 格式"YYYY-MM-DD"
     * @return 指定日期至今天的年龄
     */
    public static String countAge(String birthdayStr) {
        String age = "";
        if (birthdayStr != null && birthdayStr.length() == 8) {
            java.util.Date birthday = parseDate(birthdayStr, "YYYY-MM-DD");

            if (birthday != null) {
                Calendar calendar = Calendar.getInstance();
                int year1 = getYear();
                int month1 = StringUtil.String2Integer(getMonth2(), 0);
                int day1 = StringUtil.String2Integer(getDay2(), 00);

                calendar.setTime(birthday);
                int year2 = calendar.get(Calendar.YEAR);
                int month2 = calendar.get(Calendar.MONTH) + 1;
                int day2 = calendar.get(Calendar.DATE);

                int year = year1 - year2;
                int month = month1 - month2;
                int day = day1 - day2;

                if (month < 0) {
                    year = year - 1;
                    month = 12 + month1 - month2;
                }

                if (day < 0) {
                    month = month - 1;
                    if (month < 0) {
                        year = year - 1;
                        month = 11;
                    }
                    int lastMonthDay = 0;
                    if (month1 == 0) {
                        lastMonthDay = getDayOfMonth(12, year1 - 1);
                    } else {
                        lastMonthDay = getDayOfMonth(month1, year1);
                    }
                    day = lastMonthDay + day1 - day2;
                }

                if (year > 5) {
                    age = year + "岁";
                } else if (year > 0) {
                    if (month == 0) {
                        age = year + "岁";
                    } else {
                        age = year + "岁" + month + "月";
                    }
                } else {
                    if (month > 5) {
                        age = month + "月";
                    } else if (month > 0) {
                        age = month + "月" + day + "天";
                    } else {
                        age = day + "天";
                    }
                }
            }
        }

        return age;
    }

    /**
     * 得到指定年月的天数
     * 
     * @since 1.1
     * @param month
     *            指定月份
     * @param year
     *            指定的年份
     * @return 天数
     */
    public static int getDayOfMonth(int month, int year) {
        int ret = 0;
        boolean flag = false;

        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            flag = true;
        }

        switch (month) {
        case 1:
            ret = 31;
            break;
        case 2:
            if (flag) {
                ret = 29;
            } else {
                ret = 28;
            }
            break;
        case 3:
            ret = 31;
            break;
        case 4:
            ret = 30;
            break;
        case 5:
            ret = 31;
            break;
        case 6:
            ret = 30;
            break;
        case 7:
            ret = 31;
            break;
        case 8:
            ret = 31;
            break;
        case 9:
            ret = 30;
            break;
        case 10:
            ret = 31;
            break;
        case 11:
            ret = 30;
            break;
        case 12:
            ret = 31;
            break;
        default:
            break;
        }
        return ret;
    }

    /**
     * 计算某天是星期几
     * 
     * @since 1.1
     * @param p_date
     *            日期字符串
     * @return 星期
     */
    public static int whatDayIsSpecifyDate(String p_date) {
        // 2002-2-22 is friday5
        long differenceDays = 0L;
        long m = 0L;
        differenceDays = signDaysBetweenTowDate(p_date, "2002-2-22");

        m = (differenceDays % 7);
        m = m + 5;
        m = m > 7 ? m - 7 : m;
        return Integer.parseInt(m + "");
    }

    /**
     * 计算两日期间相差天数.
     * 
     * @since 1.1
     * @param d1
     *            日期字符串
     * @param d2
     *            日期字符串
     * @return long 天数
     */
    public static long signDaysBetweenTowDate(String d1, String d2) {
        java.sql.Date dd1 = null;
        java.sql.Date dd2 = null;
        long result = -1l;
        try {
            dd1 = java.sql.Date.valueOf(d1);
            dd2 = java.sql.Date.valueOf(d2);
            result = signDaysBetweenTowDate(dd1, dd2);
        } catch (Exception ex) {
            result = -1;
        }
        return result;
    }

    /**
     * 计算两日期间相差天数.
     * 
     * @since 1.1
     * @param d1
     *            开始日期 日期型
     * @param d2
     *            结束日期 日期型
     * @return long 天数
     */
    public static long signDaysBetweenTowDate(java.sql.Date d1, java.sql.Date d2) {
        return (d1.getTime() - d2.getTime()) / (3600 * 24 * 1000);
    }
}
j2ee常用工具_value object工具类 java J2EE常用工具类—Value Object工具类
package cn.org.jshuwei.j2ee.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

/**
* Value Object工具类<br>
* 使用实例:<br>
* 
* <pre>
* Person类:
* package cn.org.jshuwei.j2ee.util.test;
* 
* public class Person {
*     private String id;
*     private User u;
* 
*     public Person(String id, User u) {
*         super();
*         this.id = id;
*         this.u = u;
*     }
* 
*     public String getId() {
*         return id;
*     }
* 
*     public void setId(String id) {
*         this.id = id;
*     }
* 
*     public User getU() {
*         return u;
*     }
* 
*     public void setU(User u) {
*         this.u = u;
*     }
* 
* }
* User类:
* package cn.org.jshuwei.j2ee.util.test;
* 
* public class User {
*     private String userName;
*     private String userPass;
*     private Integer userAge;
*     
*     public User(){
*         
*     }
*     
*     public User(String userName, String userPass, int userAge) {
*         super();
*         this.userName = userName;
*         this.userPass = userPass;
*         this.userAge = userAge;
*     }
*     
*     public String getUserName() {
*         return userName;
*     }
*     public void setUserName(String userName) {
*         this.userName = userName;
*     }
*     public String getUserPass() {
*         return userPass;
*     }
*     public void setUserPass(String userPass) {
*         this.userPass = userPass;
*     }
*     public Integer getUserAge() {
*         return userAge;
*     }
*     public void setUserAge(Integer userAge) {
*         this.userAge = userAge;
*     }
* }
* 测试调用类:
* package cn.org.jshuwei.j2ee.util.test;
* 
* import java.util.Map;
* 
* import cn.org.jshuwei.j2ee.util.VOUtils;
* 
* public class Test {
* 
*     public static void main(String[] args) {
*         User u = new User("huwei","123",23);
*         Person p = new Person("1",u);
*         Map<String,Object> map = VOUtils.beanToMap(p,"cn.org.jshuwei.j2ee.util.test"); 
*         for(Map.Entry<String, Object> entry : map.entrySet()){   
*             String value = entry.getValue().toString();   
*             String key = entry.getKey();
*             System.out.println(key+"----"+value);
*         }
*         u = new User();
*         u.setUserName("jshuwei");
*         System.out.println(VOUtils.beanToWhereSql(u));
*     }    
* }
* </pre>
* 
* @author huwei(jshuwei.org.cn)
* 
*/
public class VOUtils {
    /**
     * 将实体类对象的属性值转换成属性名为key,属性值为value的Map<String,String>并返回
     * 
     * @param entity
     *            需要转换的实体类对象
     * @return 转换后的Map<String,String>
     */
    @SuppressWarnings("unchecked")
    public static Map<String, String> beanToMap(Object entity) {
        Class c = entity.getClass();
        Object fieldValue = null;
        String fieldName = null;
        Field[] fields = c.getDeclaredFields();
        Map<String, String> fieldMap = new HashMap<String, String>();
        for (Field field : fields) {
            fieldName = field.getName();
            if (field.getModifiers() == Modifier.PUBLIC) {
                try {
                    fieldValue = field.get(entity);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                fieldValue = invokeGet(entity, fieldName);
            }
            fieldMap.put(fieldName, fieldValue == null ? "" : fieldValue
                    .toString());
        }
        return fieldMap;
    }

    /**
     * 将实体类对象的属性值转换成属性名为key,属性值为value的Map<String,Object>并返回.
     * 其中实体类中有其他自定义对象类型的属性。
     * 
     * @param entity
     *            需要转换的实体类对象
     * @param packageName
     *            自定义对象类型属性的对象所在的包名
     * @return 转换后的Map<String,Object>
     */
    @SuppressWarnings("unchecked")
    public static Map<String, Object> beanToMap(Object entity,
            String packageName) {
        Class c = entity.getClass();
        Object fieldValue = null;
        String fieldName = null;
        Field[] fields = c.getDeclaredFields();
        Map<String, Object> fieldMap = new HashMap<String, Object>();
        for (Field field : fields) {
            fieldName = field.getName();
            if (field.getModifiers() == Modifier.PUBLIC) {
                try {
                    fieldValue = field.get(entity);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                fieldValue = invokeGet(entity, fieldName);
            }
            if (fieldValue != null
                    && fieldValue.getClass().getName().startsWith(packageName)) {
                fieldValue = beanToMap(fieldValue, packageName);
            }
            fieldMap.put(fieldName, fieldValue);
        }
        return fieldMap;
    }

    private static Object invokeGet(Object entity, String fieldName) {
        try {
            Method method = entity.getClass().getMethod(
                    "get" + StringUtil.firstToUpper(fieldName));
            return method.invoke(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 将一个实体对象(已有部分属性赋值)转换成有值属性组成的条件查询SQL语句<br>
     * <font color="red">注意:需要转换的对象的属性若是基本类型则得用包装类代替</font>
     * 
     * @param entity
     *            需要转换的实体类对象
     * @return 转换后的条件查询SQL语句字符串
     */
    public static String beanToWhereSql(Object entity) {
        StringBuffer ret = new StringBuffer(" where 1=1");
        Map<String, Object> map = beanToMap(entity, "cn.org.jshuwei.j2ee.util");
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            Object value = entry.getValue();
            String key = entry.getKey();
            if (value != null) {
                ret.append(" and ").append(key).append("=").append(value);
            }
        }
        return ret.toString();
    }
}
j2ee常用_字符串工具类 java J2EE常用工具类——字符串工具类
package cn.org.jshuwei.j2ee.util;

/**
 * 
 * 字符串操作的工具类
 * 
 * @author huwei(jshuwei.org.cn)
 * @since 1.0
 * 
 */
public class StringUtil {
	private static String strChineseFirstPY = "YDYQSXMWZSSXJBYMGCCZQPSSQBYCDSCDQLDYLYBSSJGYZZJJFKCCLZDHWDWZJLJPFYYNWJJTMYHZWZHFLZPPQHGSCYYYNJQYXXGJHHSDSJNKKTMOMLCRXYPSNQSECCQZGGLLYJLMYZZSECYKYYHQWJSSGGYXYZYJWWKDJHYCHMYXJTLXJYQBYXZLDWRDJRWYSRLDZJPCBZJJBRCFTLECZSTZFXXZHTRQHYBDLYCZSSYMMRFMYQZPWWJJYFCRWFDFZQPYDDWYXKYJAWJFFXYPSFTZYHHYZYSWCJYXSCLCXXWZZXNBGNNXBXLZSZSBSGPYSYZDHMDZBQBZCWDZZYYTZHBTSYYBZGNTNXQYWQSKBPHHLXGYBFMJEBJHHGQTJCYSXSTKZHLYCKGLYSMZXYALMELDCCXGZYRJXSDLTYZCQKCNNJWHJTZZCQLJSTSTBNXBTYXCEQXGKWJYFLZQLYHYXSPSFXLMPBYSXXXYDJCZYLLLSJXFHJXPJBTFFYABYXBHZZBJYZLWLCZGGBTSSMDTJZXPTHYQTGLJSCQFZKJZJQNLZWLSLHDZBWJNCJZYZSQQYCQYRZCJJWYBRTWPYFTWEXCSKDZCTBZHYZZYYJXZCFFZZMJYXXSDZZOTTBZLQWFCKSZSXFYRLNYJMBDTHJXSQQCCSBXYYTSYFBXDZTGBCNSLCYZZPSAZYZZSCJCSHZQYDXLBPJL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YTYTYDWEGAZYHXJLZYYHLRMGRXXZCLHNELJJTJTPWJYBJJBXJJTJTEEKHWSLJPLPSFYZPQQBDLQJJTYYQLYZKDKSQJYYQZLDQTGJQYZJSUCMRYQTHTEJMFCTYHYPKMHYZWJDQFHYYXWSHCTXRLJHQXHCCYYYJLTKTTYTMXGTCJTZAYYOCZLYLBSZYWJYTSJYHBYSHFJLYGJXXTMZYYLTXXYPZLXYJZYZYYPNHMYMDYYLBLHLSYYQQLLNJJYMSOYQBZGDLYXYLCQYXTSZEGXHZGLHWBLJHEYXTWQMAKBPQCGYSHHEGQCMWYYWLJYJHYYZLLJJYLHZYHMGSLJLJXCJJYCLYCJPCPZJZJMMYLCQLNQLJQJSXYJMLSZLJQLYCMMHCFMMFPQQMFYLQMCFFQMMMMHMZNFHHJGTTHHKHSLNCHHYQDXTMMQDCYZYXYQMYQYLTDCYYYZAZZCYMZYDLZFFFMMYCQZWZZMABTBYZTDMNZZGGDFTYPCGQYTTSSFFWFDTZQSSYSTWXJHXYTSXXYLBYQHWWKXHZXWZNNZZJZJJQJCCCHYYXBZXZCYZTLLCQXYNJYCYYCYNZZQYYYEWYCZDCJYCCHYJLBTZYYCQWMPWPYMLGKDLDLGKQQBGYCHJXY";

	/**
	 * 将一字符串转换成拼音首字母
	 * 
	 * @since 1.1
	 * @param strText
	 *            字符串
	 * @return 字符串对应的拼音首字母
	 */
	public static String getFirstPY(String strText) {
		if (strText == null || strText.trim().length() == 0)
			return "";
		String ret = "";
		for (int i = 0; i < strText.length(); i++) {
			char ch = strText.charAt(i);
			if ('\u4E00' <= ch && '\u9FA5' >= ch)
				ret = ret + strChineseFirstPY.charAt(ch - 19968);
			else
				ret = ret + ch;
		}

		return ret;
	}

	/**
	 * 替换字符串
	 * 
	 * @since 1.1
	 * @param strSc
	 *            需要进行替换的字符串
	 * @param oldStr
	 *            源字符串
	 * @param newStr
	 *            替换后的字符串
	 * @return 替换后对应的字符串
	 */
	public static String replace(String strSc, String oldStr, String newStr) {
		String ret = strSc;
		if (ret != null && oldStr != null && newStr != null) {
			ret = strSc.replaceAll(oldStr, newStr);
		}
		return ret;
	}

	/**
	 * 替换字符串,修复java.lang.String类的replaceAll方法时第一参数是字符串常量正则时(如:"address".
	 * replaceAll("dd","$");)的抛出异常:java.lang.StringIndexOutOfBoundsException:
	 * String index out of range: 1的问题。
	 * 
	 * @since 1.2
	 * @param strSc
	 *            需要进行替换的字符串
	 * @param oldStr
	 *            源字符串
	 * @param newStr
	 *            替换后的字符串
	 * @return 替换后对应的字符串
	 */
	public static String replaceAll(String strSc, String oldStr, String newStr) {
		int i = -1;
		while ((i = strSc.indexOf(oldStr)) != -1) {
			strSc = new StringBuffer(strSc.substring(0, i)).append(newStr)
					.append(strSc.substring(i + oldStr.length())).toString();
		}
		return strSc;
	}

	/**
	 * 将字符串转换成HTML格式的字符串
	 * 
	 * @since 1.1
	 * @param str
	 *            需要进行转换的字符串
	 * @return 转换后的字符串
	 */
	public static String toHtml(String str) {
		String html = str;
		if (str == null || str.length() == 0) {
			return "";
		} else {
			html = replace(html, "&", "&amp;");
			html = replace(html, "<", "&lt;");
			html = replace(html, ">", "&gt;");
			html = replace(html, "\r\n", "\n");
			html = replace(html, "\n", "<br>\n");
			html = replace(html, "\"", "&quot;");
			html = replace(html, " ", "&nbsp;");
			return html;
		}
	}

	/**
	 * 将HTML格式的字符串转换成常规显示的字符串
	 * 
	 * @since 1.1
	 * @param str
	 *            需要进行转换的字符串
	 * @return 转换后的字符串
	 */
	public static String toText(String str) {
		String text = str;
		if (str == null || str.length() == 0) {
			return "";
		} else {
			text = replace(text, "&amp;", "&");
			text = replace(text, "&lt;", "<");
			text = replace(text, "&gt;", ">");
			text = replace(text, "<br>\n", "\n");
			text = replace(text, "<br>", "\n");
			text = replace(text, "&quot;", "\"");
			text = replace(text, "&nbsp;", " ");
			return text;
		}
	}

	/**
	 * 将一字符串数组以某特定的字符串作为分隔来变成字符串
	 * 
	 * @since 1.0
	 * @param strs
	 *            字符串数组
	 * @param token
	 *            分隔字符串
	 * @return 以token为分隔的字符串
	 */
	public static String join(String[] strs, String token) {
		if (strs == null)
			return null;
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < strs.length; i++) {
			if (i != 0)
				sb.append(token);
			sb.append(strs[i]);
		}
		return sb.toString();
	}

	/**
	 * 将一字符串以某特定的字符串作为分隔来变成字符串数组
	 * 
	 * @since 1.0
	 * @param str
	 *            需要拆分的字符串("@12@34@56")
	 * @param token
	 *            分隔字符串("@")
	 * @return 以token为分隔的拆分开的字符串数组
	 */
	public static String[] split(String str, String token) {
		String temp = str.substring(1, str.length());
		return temp.split(token);
	}

	/**
	 * 验证字符串合法性
	 * 
	 * @since 1.0
	 * @param str
	 *            需要验证的字符串
	 * @param test
	 *            非法字符串(如:"~!#$%^&*()',;:?")
	 * @return true:非法;false:合法
	 */
	public static boolean check(String str, String test) {
		if (str == null || str.equals(""))
			return true;
		boolean flag = false;
		for (int i = 0; i < test.length(); i++) {
			if (str.indexOf(test.charAt(i)) != -1) {
				flag = true;
				break;
			}
		}
		return flag;
	}

	/**
	 * 将数值型字符串转换成Integer型
	 * 
	 * @since 1.0
	 * @param str
	 *            需要转换的字符型字符串
	 * @param ret
	 *            转换失败时返回的值
	 * @return 成功则返回转换后的Integer型值;失败则返回ret
	 */
	public static Integer String2Integer(String str, Integer ret) {
		try {
			return Integer.parseInt(str);
		} catch (NumberFormatException e) {
			return ret;
		}
	}

	/**
	 * 将数值型转换成字符串
	 * 
	 * @since 1.0
	 * @param it
	 *            需要转换的Integer型值
	 * @param ret
	 *            转换失败的返回值
	 * @return 成功则返回转换后的字符串;失败则返回ret
	 */
	public static String Integer2String(Integer it, String ret) {
		try {
			return Integer.toString(it);
		} catch (NumberFormatException e) {
			return ret;
		}
	}

	/**
	 * 比较两字符串大小(ASCII码顺序)
	 * 
	 * @since 1.1
	 * @param str1
	 *            参与比较的字符串1
	 * @param str2
	 *            参与比较的字符串2
	 * @return str1>str2:1;str1<str2:-1;str1=str2:0
	 */
	public static int compare(String str1, String str2) {//
		if (str1.equals(str2)) {
			return 0;
		}
		int str1Length = str1.length();
		int str2Length = str2.length();
		int length = 0;
		if (str1Length > str2Length) {
			length = str2Length;
		} else {
			length = str1Length;
		}
		for (int i = 0; i < length; i++) {
			if (str1.charAt(i) > str2.charAt(i)) {
				return 1;
			}
		}
		return -1;
	}

	/**
	 * 将阿拉伯数字的钱数转换成中文方式
	 * 
	 * @since 1.1
	 * @param num
	 *            需要转换的钱的阿拉伯数字形式
	 * @return 转换后的中文形式
	 */
	public static String num2Chinese(double num) {
		String result = "";
		String str = Double.toString(num);
		if (str.contains(".")) {
			String begin = str.substring(0, str.indexOf("."));
			String end = str.substring(str.indexOf(".") + 1, str.length());
			byte[] b = begin.getBytes();
			int j = b.length;
			for (int i = 0, k = j; i < j; i++, k--) {
				result += getConvert(begin.charAt(i));
				if (!"零".equals(result.charAt(result.length() - 1) + "")) {
					result += getWei(k);
				}
				System.out.println(result);

			}
			for (int i = 0; i < result.length(); i++) {
				result = result.replaceAll("零零", "零");
			}
			if ("零".equals(result.charAt(result.length() - 1) + "")) {
				result = result.substring(0, result.length() - 1);
			}
			result += "元";
			byte[] bb = end.getBytes();
			int jj = bb.length;
			for (int i = 0, k = jj; i < jj; i++, k--) {
				result += getConvert(end.charAt(i));
				if (bb.length == 1) {
					result += "角";
				} else if (bb.length == 2) {
					result += getFloat(k);
				}
			}
		} else {
			byte[] b = str.getBytes();
			int j = b.length;
			for (int i = 0, k = j; i < j; i++, k--) {
				result += getConvert(str.charAt(i));
				result += getWei(k);
			}
		}
		return result;
	}

	private static String getConvert(char num) {
		if (num == '0') {
			return "零";
		} else if (num == '1') {
			return "一";
		} else if (num == '2') {
			return "二";
		} else if (num == '3') {
			return "三";
		} else if (num == '4') {
			return "四";
		} else if (num == '5') {
			return "五";
		} else if (num == '6') {
			return "六";
		} else if (num == '7') {
			return "七";
		} else if (num == '8') {
			return "八";
		} else if (num == '9') {
			return "九";
		} else {
			return "";
		}
	}

	private static String getFloat(int num) {
		if (num == 2) {
			return "角";
		} else if (num == 1) {
			return "分";
		} else {
			return "";
		}
	}

	private static String getWei(int num) {
		if (num == 1) {
			return "";
		} else if (num == 2) {
			return "十";
		} else if (num == 3) {
			return "百";
		} else if (num == 4) {
			return "千";
		} else if (num == 5) {
			return "万";
		} else if (num == 6) {
			return "十";
		} else if (num == 7) {
			return "百";
		} else if (num == 8) {
			return "千";
		} else if (num == 9) {
			return "亿";
		} else if (num == 10) {
			return "十";
		} else if (num == 11) {
			return "百";
		} else if (num == 12) {
			return "千";
		} else if (num == 13) {
			return "兆";
		} else {
			return "";
		}
	}
	/**
	 * 将字符串的首字母改为大写
	 * 
	 * @since 1.2
	 * @param str
	 *            需要改写的字符串
	 * @return 改写后的字符串
	 */
	public static String firstToUpper(String str){
		return str.substring(0,1).toUpperCase()+str.substring(1);
	}
}
j2ee常用工具_jdbc操作 java J2EE常用工具类—Jdbc操作
package cn.org.jshuwei.j2ee.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

/**
* 
* Jdbc操作的工具类
* 
* @author huwei(jshuwei.org.cn)
* @since 1.0
* 
*/
public class JdbcUtil {
    static {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Class.forName("com.mysql.jdbc.Driver");
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 得到Connection
     * 
     * @since 1.0
     * @param dbType
     *            数据库类型(oracle/mysql)
     * @return 返回Connection
     */
    public static Connection getConnection(String dbType) {
        String url = "";
        String user = "";
        String password = "";
        if (dbType.equals("oracle")) {
            url = "jdbc:oracle:thin:@localhost:6666:XE";
            user = "jshuwei";
            password = "123456";
        }
        if (dbType.equals("mysql")) {
            url = "jdbc:mysql://localhost:3306/test";
            user = "jshuwei";
            password = "123456";
        }
        if (dbType.equals("sqlServer")) {
            url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_test";
            user = "jshuwei";
            password = "123456";
        }
        try {
            return DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 打印记录集对象
     * 
     * @since 1.0
     * @param rs
     *            需要打印的记录集对象
     */
    public static void printRs(ResultSet rs) {
        if (rs == null) {
            System.out.println("ResultSet is null!");
            return;
        }
        try {
            ResultSetMetaData md = rs.getMetaData();
            int cols = md.getColumnCount();
            for (int i = 1; i <= cols; i++) {
                // 列名,类型编号,类型名称
                System.out
                        .println(md.getColumnName(i) + "-->"
                                + md.getColumnType(i) + "-->"
                                + md.getColumnTypeName(i));
            }
            System.out.println("=========================================");
            while (rs.next()) {
                for (int i = 1; i <= cols; i++) {
                    System.out.println(md.getColumnName(i) + "="
                            + rs.getString(i) + "\t");
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 释放资源
     * 
     * @since 1.0
     * @param rs
     *            需要释放的记录集对象
     * @param stmt
     *            需要释放的Statement对象
     * @param con
     *            需要释放的连接对象
     */
    public static void release(ResultSet rs, Statement stmt, Connection con) {
        if (rs != null)
            try {
                rs.close();
            } catch (Exception e) {
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
            }
        if (con != null)
            try {
                con.close();
            } catch (Exception e) {
            }
    }

    /**
     * 释放资源
     * 
     * @since 1.0
     * @param o
     *            需要释放的对象
     */
    public static void release(Object o) {
        try {
            if (o instanceof ResultSet) {
                ((ResultSet) o).close();
            } else if (o instanceof Statement) {
                ((Statement) o).close();
            } else if (o instanceof Connection) {
                ((Connection) o).close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
j2ee常用工具_md5加密 java J2EE常用工具类——MD5加密
package cn.org.jshuwei.j2ee.util;

import java.security.MessageDigest;

/**
* 
* MD5加密工具类
* 
* @author huwei(jshuwei.org.cn)
* @since 1.4
* 
*/
public class MD5 {
    private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5",
            "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };

    private static String byteArrayToHexString(byte[] bytes) {
        StringBuffer sb = new StringBuffer();
        for (byte b : bytes) {
            sb.append(byteToHexString(b));
        }
        return sb.toString();
    }

    private static String byteToHexString(byte b) {
        int n = b;
        if (n < 0)
            n = 256 + n;
        int d1 = n / 16;
        int d2 = n % 16;
        return hexDigits[d1] + hexDigits[d2];
    }

    /**
     * 将字符串加密成MD5字符串
     * 
     * @param origin
     *            需要加密的字符串
     * @return 加密后的字符串
     */
    public static String MD5Encode(String origin) {
        String ret = null;
        try {
            ret = new String(origin);
            MessageDigest md = MessageDigest.getInstance("MD5");
            ret = byteArrayToHexString(md.digest(ret.getBytes()));
        } catch (Exception e) {
        }
        return ret;
    }
}
java通用工具类(二) java Java通用工具类(一)------常用工具类
package com.travel.tools.database;

import java.text.*;
import java.util.*;

/**
 * 
 * <p>
 * Title: 通用工具类
 * </p>
 * <p>
 * Description: 常用工具的集合,用来处理常见问题,比如中文乱码的方法等。
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003
 * </p>
 * <p>
 * Company: Towery
 * </p>
 * 
 * @author WangPinHeng
 * @version 1.0
 */
public class Tools {
    public Tools() {
        //
    }

    /**
     * 字符串替换,将 source 中的 oldString 全部换成 newString
     * 
     * @param source
     *            源字符串
     * @param oldString
     *            老的字符串
     * @param newString
     *            新的字符串
     * @return 替换后的字符串
     */
    private static String Replace(String source, String oldString,
            String newString) {
        StringBuffer output = new StringBuffer();

        int lengthOfSource = source.length(); // 源字符串长度
        int lengthOfOld = oldString.length(); // 老字符串长度

        int posStart = 0; // 开始搜索位置
        int pos; // 搜索到老字符串的位置

        while ((pos = source.indexOf(oldString, posStart)) >= 0) {
            output.append(source.substring(posStart, pos));

            output.append(newString);
            posStart = pos + lengthOfOld;
        }

        if (posStart < lengthOfSource) {
            output.append(source.substring(posStart));
        }

        return output.toString();
    }

    /**
     * 转换SQL中的特殊符号,比如将单引号"'"替换为"''",以免产生SQLException
     * 
     * @param sqlstr
     *            原SQL
     * @return 处理后的SQL
     */
    public static String toSql(String sqlstr) {
        String strsql = sqlstr;
        if (strsql == null) {
            return "";
        }
        strsql = Replace(strsql, "'", "''");
        return strsql;
    }

    /**
     * 将ISO8859_1编码的字符串转化为GB2312编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param ISO8859_1str
     *            通过ISO8859_1编码的字符串
     * @return 通过GB2312编码的字符串
     */
    public String GBString(String ISO8859_1str) {
        if (ISO8859_1str == null) {
            return "";
        } else {
            try {
                return new String(ISO8859_1str.getBytes("ISO8859_1"), "GB2312");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将ISO8859_1编码的字符串转化为GB2312编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param ISO8859_1str
     *            通过ISO8859_1编码的字符串
     * @return 通过GB2312编码的字符串
     */
    public static String GB2312FromISO8859_1(String ISO8859_1str) {
        if (ISO8859_1str == null) {
            return "";
        } else {
            try {
                return new String(ISO8859_1str.getBytes("ISO8859_1"), "GB2312");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    public String trim1(String str) {
        String str1 = "";

        if (str.substring(0, 1).equals("?")) {
            str1 = str.substring(1, str.length());
            System.out.println("str1=" + str1);
        } else {
            str1 = str;
        }

        return str1.trim();
    }

    public String dateformat(String str) {
        String day = str.substring(0, 2);
        String month = str.substring(3, 5);
        String year = str.substring(6, 10);
        str = year + "-" + month + "-" + day;
        return str;
    }

    public String tenformat(String str) {
        if (str.length() == 8) {
            String year = str.substring(0, 4);
            String month = "0" + str.substring(5, 6);
            String day = "0" + str.substring(7, 8);
            str = year + "-" + month + "-" + day;
        } else if (str.length() == 9) {
            if (str.substring(6, 7).equals("-")) {
                str = str.substring(0, 5) + "0" + str.substring(5, 9);
            } else {
                str = str.substring(0, 8) + "0" + str.substring(8, 9);
            }

        }
        return str;
    }

    /**
     * 计算两个时间
     * 
     * @param str
     *            原时间,strsub,需减少的时间
     * @return 计算后的时间
     */
    public String subTime(String str, String strSub) {
        String rsTime = "";
        int hour = 0;
        int sec = 0;
        int secsub = 0;
        str = trim(str);
        strSub = trim(strSub);
        if (str.length() == 5) {
            hour = Integer.parseInt(str.substring(0, 2));

            sec = Integer.parseInt(str.substring(3, 5));

        } else if (str.length() == 4) {
            hour = Integer.parseInt(str.substring(0, 1));

            sec = Integer.parseInt(str.substring(2, 4));

        }
        if (trim(strSub).length() == 5) {
            secsub = Integer.parseInt(strSub.substring(0, 2));

        } else if (trim(strSub).length() == 4) {
            secsub = Integer.parseInt(strSub.substring(0, 1));

        }

        //int a = sec + secsub;
        if (sec < secsub) {
            //System.out.println("sub <");
            String jstr = Integer.toString(sec + 60 - secsub);
            String hstr = Integer.toString(hour - 1);
            //System.out.println("jstr="+jstr);
            //System.out.println("hstr="+hstr);
            if (jstr.length() == 1) {
                jstr = "0" + jstr;
            }
            if (hstr.length() == 1) {
                hstr = "0" + hstr;
            }
            rsTime = hstr + ":" + jstr;

        } else if (sec == secsub) {
            //System.out.println("sub =");
            String strh = Integer.toString(hour);
            //System.out.println("strh="+strh);
            if (strh.length() == 1) {
                strh = "0" + strh;
            }
            rsTime = strh + ":00";

        } else if (sec > secsub) {
            //System.out.println("sub >");
            String jstr = Integer.toString(sec - secsub);
            //System.out.println("jstr="+jstr);
            String hstr = Integer.toString(hour);
            //System.out.println("hstr="+hstr);
            if (jstr.length() == 1) {
                jstr = "0" + jstr;
            }
            if (hstr.length() == 1) {
                hstr = "0" + hstr;
            }
            rsTime = hstr + ":" + jstr;

        }
        return rsTime;
    }

    public String toSENDstr(String input) {
        String r = input;
        r = replace(r, "&", "");
        r = replace(r, "/", "|");
        r = replace(r, "\r", "");
        r = replace(r, "\n", "");
        r = replace(r, "'", "");
        r = replace(r, " ", "");
        return r;
    }

    public String replace(String str, String strOld, String strNew) {
        String r = str;
        if (str != null && strOld != null && strNew != null) {
            int idx = str.indexOf(strOld);
            if (idx != -1) {
                String strPre = "";
                r = "";
                String strSuf = str;
                for (; idx != -1; idx = strSuf.indexOf(strOld)) {
                    strPre = strSuf.substring(0, idx);
                    strSuf = strSuf.substring(idx + strOld.length());
                    r = r + strPre + strNew;
                }

                r = r + strSuf;
            }
        }
        return r;
    }

    /**
     * 计算两个时间相差的分钟数
     * 
     * @param time1
     *            string,time2,string
     * @return string
     */
    public String diffTime(String time1, String time2) {
        String rsTime = "";
        int hour = 0;
        int hour2 = 0;
        int sec = 0;
        int sec2 = 0;
        String str1 = trim(time1);
        String str2 = trim(time2);
        if (str1.length() == 5) {
            hour = Integer.parseInt(str1.substring(0, 2));

            sec = Integer.parseInt(str1.substring(3, 5));

        } else if (str1.length() == 4) {
            hour = Integer.parseInt(str1.substring(0, 1));

            sec = Integer.parseInt(str1.substring(2, 4));

        }
        if (str2.length() == 5) {
            hour2 = Integer.parseInt(str2.substring(0, 2));

            sec2 = Integer.parseInt(str2.substring(3, 5));

        } else if (str2.length() == 4) {
            hour2 = Integer.parseInt(str2.substring(0, 1));

            sec2 = Integer.parseInt(str2.substring(2, 4));

        }

        //int a = sec + secsub;
        if (sec < sec2) {
            //System.out.println("sub <");
            String jstr = Integer.toString(sec + 60 - sec2);
            if (jstr.length() == 1) {
                jstr = "0" + jstr;
            }
            if ((hour - 1) != hour2) {

                String hstr = Integer.toString(hour - 1 - hour2);

                if (hstr.length() == 1) {
                    hstr = "0" + hstr;
                }
                rsTime = hstr + ":" + jstr + ":00";
            } else {
                rsTime = jstr + ":00";
            }
        } else if (sec == sec2) {
            //System.out.println("sub =");
            if (hour != hour2) {

                String strh = Integer.toString(hour - hour2);
                //System.out.println("strh="+strh);
                if (strh.length() == 1) {
                    strh = "0" + strh;
                }
                rsTime = strh + ":00" + ":00";
            } else {
                rsTime = "00:00";
            }
        } else if (sec > sec2) {
            //System.out.println("sub >");
            String jstr = Integer.toString(sec - sec2);
            //System.out.println("jstr="+jstr);
            if (jstr.length() == 1) {
                jstr = "0" + jstr;
            }
            if (hour != hour2) {
                String hstr = Integer.toString(hour - hour2);
                //System.out.println("hstr="+hstr);
                if (hstr.length() == 1) {
                    hstr = "0" + hstr;
                }
                rsTime = hstr + ":" + jstr + ":00";
            } else {
                rsTime = jstr + ":00";
            }
        }
        return rsTime;
    }

    /**
     * 计算两个时间
     * 
     * @param str
     *            原时间,stradd,需增加的时间
     * @return 计算后的时间
     */
    public String addTime(String str, String stradd) {
        String rsTime = "";
        int hour = 0;
        int sec = 0;
        int secadd = 0;
        int houradd = 0;
        str = trim(str);
        stradd = trim(stradd);
        if (str.length() == 5) {
            hour = Integer.parseInt(str.substring(0, 2));

            sec = Integer.parseInt(str.substring(3, 5));

        } else if (str.length() == 4) {
            hour = Integer.parseInt(str.substring(0, 1));

            sec = Integer.parseInt(str.substring(2, 4));

        }
        if (trim(stradd).length() == 5) {

            secadd = Integer.parseInt(stradd.substring(0, 2));

        } else if (trim(stradd).length() == 4) {
            secadd = Integer.parseInt(stradd.substring(0, 1));

        } else if (trim(stradd).length() == 7) {
            houradd = Integer.parseInt(stradd.substring(0, 1));
            secadd = Integer.parseInt(stradd.substring(2, 4));
        }
        int a = sec + secadd;
        if (a < 60) {
            String stra = Integer.toString(a);
            String strh = Integer.toString(hour + houradd);
            if (stra.length() == 1) {
                stra = "0" + stra;
            }
            if (strh.length() == 1) {
                strh = "0" + strh;
            } else if (Integer.parseInt(strh) > 24) {
                int h = Integer.parseInt(strh) / 24;
                strh = Integer.toString(h);
                if (h < 10) {
                    strh = "0" + Integer.toString(h);
                }
            }
            rsTime = strh + ":" + stra;

        } else if (a == 60) {
            String strh = Integer.toString(hour + houradd + 1);
            if (strh.length() == 1) {
                strh = "0" + strh;
            } else if (Integer.parseInt(strh) > 24) {
                int h = Integer.parseInt(strh) / 24;
                strh = Integer.toString(h);
                if (h < 10) {
                    strh = "0" + Integer.toString(h);
                }
            }
            rsTime = strh + ":00";

        } else if (a > 60) {
            int i = a / 60;
            int j = a % 60;
            String strj = Integer.toString(j);

            if (strj.length() == 1) {
                strj = "0" + strj;
            }
            String strh = Integer.toString(hour + houradd + i);
            if (strh.length() == 1) {
                strh = "0" + strh;
            } else if (Integer.parseInt(strh) > 24) {
                int h = Integer.parseInt(strh) / 24;
                strh = Integer.toString(h);
                if (h < 10) {
                    strh = "0" + Integer.toString(h);
                }
            }
            rsTime = strh + ":" + strj;

            if (j == 0) {
                rsTime = strh + ":00";

            }

        }
        return rsTime;
    }

    /**
     * 将UTF编码的字符串转化为GB2312编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param UTF
     *            通过UTF编码的字符串
     * @return 通过GB2312编码的字符串
     */
    public static String GB2312FromUTF(String UTF) {
        if (UTF == null) {
            return "";
        } else {
            try {
                return new String(UTF.getBytes("UTF-8"), "GB2312");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将GB2312编码的字符串转化为UTF-8编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param GB2312
     *            通过GB2312编码的字符串
     * @return 通过UTF-8编码的字符串
     */
    public static String UTFFromGB2312(String GB2312) {
        if (GB2312 == null) {
            return "";
        } else {
            try {
                return new String(GB2312.getBytes("GB2312"), "UTF-8");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    public static String GBKFromISO8859_1(String ISO8859_1) {
        if (ISO8859_1 == null) {
            return "";
        } else {
            try {
                return new String(ISO8859_1.getBytes("ISO8859_1"), "GBK");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    public static String GBKFromUTF(String UTF) {
        if (UTF == null) {
            return "";
        } else {
            try {
                return new String(UTF.getBytes("UTF-8"), "GBK");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将ISO8859_1编码的字符串转化为UTF-8编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param ISO8859_1str
     *            通过ISO8859_1编码的字符串
     * @return 通过UTF-8编码的字符串
     */
    public static String UTFFromISO8859_1(String ISO8859_1str) {
        return ISO8859_1str;
    }

    public static String UTFFromGBK(String GBK) {
        if (GBK == null) {
            return "";
        } else {
            try {
                return new String(GBK.getBytes("GBK"), "UTF-8");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将UTF-8编码的字符串转化为ISO8859_1编码的字符串,主要用来处理中文显示乱码的问题
     * 
     * @param UTF
     *            通过UTF编码的字符串
     * @return 通过ISO8859_1编码的字符串
     */
    public static String ISO8859_1FromUTF(String UTFstr) {
        if (UTFstr == null) {
            return "";
        } else {
            try {
                return new String(UTFstr.getBytes("UTF-8"), "ISO8859_1");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将GB2312编码的字符串转化为ISO8859_1编码的字符串
     * 
     * @param GBstr
     *            GB2312编码的字符串
     * @return ISO8859_1编码的字符串
     */
    public static String ISO8859_1String(String GBstr) {
        if (GBstr == null) {
            return "";
        } else {
            try {
                return new String(GBstr.getBytes("GB2312"), "ISO8859_1");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 将GB2312编码的字符串转化为ISO8859_1编码的字符串
     * 
     * @param GBstr
     *            GB2312编码的字符串
     * @return ISO8859_1编码的字符串
     */
    public String ISO8859_1FromGB2312(String GBstr) {
        if (GBstr == null) {
            return "";
        } else {
            try {
                return new String(GBstr.getBytes("GB2312"), "ISO8859_1");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    public static String ISO8859_1FromGBK(String GBK) {
        if (GBK == null) {
            return "";
        } else {
            try {
                return new String(GBK.getBytes("GBK"), "ISO8859_1");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    /**
     * 去除字符串两端空格。
     * 
     * @param str
     *            需要处理的字符串
     * @return 去掉了两端空格的字符串,如果str 为 null 则返回 ""
     */
    public static String trim(String str) {
        if (str != null) {
            return str.trim();
        } else {
            return "";
        }
    }

    //  static public String mm_dd_yyyy = "MM-dd-yyyy HH:mm:ss";
    /**
     * 获得当前年份
     * 
     * @return 当前年份,格式如:2003
     */
    public static int getCurrentYear() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
        return Integer.parseInt(sdf.format(new java.util.Date()));
    }

    /**
     * 获得当前月份
     * 
     * @return 当前月份
     */
    public static int getCurrentMonth() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("M");
        return Integer.parseInt(sdf.format(new java.util.Date()));
    }

    /**
     * 获得当前天
     * 
     * @return 当前天
     */
    public static int getCurrentDay() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DATE);
    }

    public static String getCurrentDateTime() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd H:mm");
        return sdf.format(new Date());
    }

    /**
     * 获得形如 19770608 格式的当前年月日
     * 
     * @return 当前年月日
     */
    public static String getSimpleCurrentDate() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyyMMdd HH:mm:ss");
        return sdf.format(new java.util.Date());
    }

    /**
     * 返回两个日期相差天数
     * 
     * @param d1
     *            日期
     * @param d2
     *            日期
     * @return 天数
     */
    public int diffDate(Date d1, Date d2) {
        if ((d1 == null) || (d2 == null))
            return 0;

        Calendar cal = Calendar.getInstance();

        // from Locale, has nothing to do with your input date format
        int zoneoffset = cal.get(Calendar.ZONE_OFFSET);
        int dstoffset = cal.get(Calendar.DST_OFFSET);

        // getTime() return absolute GMT time
        // compensate with the offsets
        long dl1 = d1.getTime() + zoneoffset + dstoffset;
        long dl2 = d2.getTime() + zoneoffset + dstoffset;

        int intDaysFirst = (int) (dl1 / (60 * 60 * 1000 * 24)); //60*60*1000
        int intDaysSecond = (int) (dl2 / (60 * 60 * 1000 * 24));

        return intDaysFirst > intDaysSecond ? intDaysFirst - intDaysSecond
                : intDaysSecond - intDaysFirst;
    }

    /**
     * 将给定的时间转换为格式是8位的字符串
     * 
     * @param date
     *            给定的时间
     * @return 格式化后的字符串形式的时间
     */
    public String get8BitDate(java.util.Date date) {
        if (date == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyyMMdd");
        return sdf.format(date);
    }

    public String to_date(String strdate, String df) {
        if (strdate == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat(
                "M/d/yyyy H:m:s");
        Date d = null;
        try {
            d = sdf1.parse(strdate);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return sdf.format(d);
    }

    public static String get8BitString(String strDate) {
        if (strDate == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat(
                "yyyyMMdd");
        Date d = null;
        try {
            d = sdf.parse(strDate);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return sdf2.format(d);
    }

    public static String get8ByteTo10Byte(String strDate) {
        if (strDate == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyyMMdd");
        java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        Date d = null;
        try {
            d = sdf.parse(strDate);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return sdf2.format(d);
    }

    public static String getStandedDateTime(String strDate) {
        if (strDate == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        Date d = null;
        try {
            d = sdf.parse(strDate);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return sdf2.format(d);
    }

    public static String getMonthDay(java.util.Date date) {
        if (date == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("M月d日");
        return sdf.format(date);
    }

    public static String getHourMinute(java.util.Date date) {
        if (date == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("H:mm");
        return sdf.format(date);
    }

    /**
     * 判断字符串是否符合日期格式
     * 
     * @param str
     *            字符串时间
     * @return
     */
    public static boolean isDate(String strDate) {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        sdf.setLenient(false);
        try {
            sdf.parse(strDate);
            return true;
        } catch (ParseException ex) {
            return false;
        }
    }

    /**
     * 判断是否是数字
     * 
     * @param str
     * @return
     */
    public static boolean isNumber(String strNumber) {
        boolean bolResult = false;
        try {
            Double.parseDouble(strNumber);
            bolResult = true;
        } catch (NumberFormatException ex) {
            bolResult = false;
        }
        return bolResult;
    }

    public String dateadd(Date strDate, int a) {
        String str = "";

        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        String strDate1 = sdf.format(strDate);

        int year = Integer.parseInt(strDate1.substring(0, 4));
        int month = Integer.parseInt(strDate1.substring(5, 7));
        int day = Integer.parseInt(strDate1.substring(8, 10));
        int md = getdayformonth(month);
        int i = (day + a) / md;
        int j = (day + a) % md;
        if (j == 0) {
            i = i - 1;
            j = md;
        }
        String strmon = "";
        String strday = "";
        String mondiff = "";
        if (i < 2) {
            if (Integer.toString(j).length() == 1) {
                strday = "0" + Integer.toString(j);
            } else {
                strday = Integer.toString(j);
            }
            if ((month + i) > 12) {
                int yeardiff = (month + i) / 12;
                int monthmod = (month + i) % 12;
                mondiff = Integer.toString(monthmod);
                if (Integer.toString(monthmod).length() == 1) {
                    mondiff = "0" + Integer.toString(monthmod);
                }
                str = Integer.toString(year + yeardiff) + "-" + mondiff + "-"
                        + strday;
            } else {
                strmon = Integer.toString(month + i);
                if (Integer.toString(month + i).length() == 1) {
                    strmon = "0" + Integer.toString(month + i);
                }

                str = Integer.toString(year) + "-" + strmon + "-" + strday;

            }
        } else {
            //主要判断假如天数,月份溢出的处理,
        }
        return str;
    }

    public int getdayformonth(int month) {
        int a = 0;
        switch (month) {
        case 1:
            a = 31;
            break;
        case 2:
            a = 28;
            break;
        case 3:
            a = 31;
            break;
        case 4:
            a = 30;
            break;
        case 5:
            a = 31;
            break;
        case 6:
            a = 30;
            break;
        case 7:
            a = 31;
            break;
        case 8:
            a = 31;
            break;
        case 9:
            a = 30;
            break;
        case 10:
            a = 31;
            break;
        case 11:
            a = 30;
            break;
        case 12:
            a = 31;
            break;
        default:

        }
        return a;
    }

    public String addOneDay(String strDate) //YYYY-MM-DD
    {
        int[] standardDays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] leapyearDays = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int y = Integer.parseInt(strDate.substring(0, 4));
        int m = Integer.parseInt(strDate.substring(4, 6));
        int d = Integer.parseInt(strDate.substring(6, 8)) + 1;
        int maxDateCount = 0;

        System.out.println(y);
        System.out.println(m);
        System.out.println(d);

        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
            maxDateCount = leapyearDays[m - 1];
        } else {
            maxDateCount = standardDays[m - 1];
        }

        if (d > maxDateCount) {
            d = 1;
            m++;
        }

        if (m > 12) {
            m = 1;
            y++;
        }
        java.text.DecimalFormat yf = new java.text.DecimalFormat("0000");
        java.text.DecimalFormat mdf = new java.text.DecimalFormat("00");
        return yf.format(y) + mdf.format(m) + mdf.format(d);
    }

    public static String subOneDay(String strDate) {
        //YYYY-MM-DD
        int[] standardDays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] leapyearDays = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int y = Integer.parseInt(strDate.substring(0, 4));
        int m = Integer.parseInt(strDate.substring(4, 6));
        int d = Integer.parseInt(strDate.substring(6, 8)) - 1;
        int maxDateCount = 0;

        System.out.println(y);
        System.out.println(m);
        System.out.println(d);

        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
            maxDateCount = leapyearDays[m - 1];
        } else {
            maxDateCount = standardDays[m - 1];
        }

        if (d > maxDateCount) {
            d = 1;
            m++;
        }

        if (m > 12) {
            m = 1;
            y++;
        }
        java.text.DecimalFormat yf = new java.text.DecimalFormat("0000");
        java.text.DecimalFormat mdf = new java.text.DecimalFormat("00");
        return yf.format(y) + mdf.format(m) + mdf.format(d);
    }

    public static void main(String[] argv) {
        System.out.println(Tools.getMonthDay(new java.util.Date()));
        System.out.println(Tools.getHourMinute(new java.util.Date()));
       
    }
}




本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/success_dream/archive/2006/11/25/1413521.aspx
字符处理,常用工具类(一) java 字符处理,常用工具类(一)
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.pro.utils.ApplicationUtil;

/***
 * 常用工具类(一)
 * 
 * @author Administrator
 * @lastEdittime 2010-09-01
 * 
 */
public class StringUtil {
	// 字符串截取
	public static String cutString(Object obj, int count) {
		if (obj.toString().length() > count - 2) {
			return obj.toString().substring(0, count - 2) + "..."; // 带省略形式

		} else {
			return obj.toString();
		}
	}

	// 字符截取2
	public static String cutString2(Object obj, int count) {
		if (obj.toString().length() > count - 2) {
			return obj.toString().substring(0, count - 2); // 不带省略形式
		} else {
			return obj.toString();
		}
	}

	// 字符为空判断
	public static boolean isNull(Object obj) {
		return obj == null;
	}

	public static boolean isNull(String obj) {
		return obj == null || obj.trim().length() == 0;
	}

	/***
	 * 由下标,得到元素(用于二维数组) ,获取行业类型
	 * 
	 * @param id
	 * @return
	 */
	public static String getDistrictIndustryArray(String id) {
		String msg = "";
		for (String[] arr : ApplicationUtil.industryArray) {
			if (arr[0].equals(id)) {
				msg = arr[1];
				break;
			}
		}
		return msg;
	}

	/***
	 * 由下标,得到元素(用于二维数组) ,获取企业规模
	 * 
	 * @param id
	 * @return
	 */
	public static String getDistrictEnterprisescales(String id) {
		String msg = "";
		for (String[] arr : ApplicationUtil.enterprisescales) {
			if (arr[0].equals(id)) {
				msg = arr[1];
				break;
			}
		}
		return msg;
	}

	/***
	 * 特殊字符过滤
	 * 
	 * @param obj
	 * @return 过滤结果
	 */
	public static String getStringFilter(Object obj) {
		String regExp = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
		Pattern patternObj = Pattern.compile(regExp);
		Matcher matcher = patternObj.matcher(obj.toString()); // 匹配处理
		return matcher.replaceAll(" ").trim();
	}

	/***
	 * 字符限制
	 * 
	 * @param obj
	 * @param count
	 * @param sumcount
	 * @return obj
	 */
	public static String getStringLimit(Object obj, int count) {

		if (obj.toString().length() > count) {
			return obj.toString().substring(0, count);
		} else {
			return obj.toString();
		}
	}

	/**
	 * 时间处理
	 */
	public static String getFormatDate(Date date, String dateFormatString) {
		try {
			return new java.text.SimpleDateFormat(dateFormatString)
					.format(date);
		} catch (Exception e) {
		}
		return null;
	}


java常用工具类例子 java java常用工具类例子
package test;

import java.text.MessageFormat;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestUtil {
	public static void main(String[] args) {
		Pattern p = Pattern.compile("list_\\d+_start");
		Matcher m = p.matcher("list_01_start");
		System.out.println(m.matches());
		
		MessageFormat mf = new MessageFormat("{0}がNULLなので、{1}が異常終了する。");
		String mfStr = mf.format(new Object[]{"引数","処理"});
		System.out.println(mfStr);
		
		ResourceBundle rb = ResourceBundle.getBundle("TestResource");
		String message = rb.getString("ErrorMessage_001");
		System.out.println(message);
	}
}
java工具类 java java常用工具类
import java.text.*;
import java.util.*;

/**
*
* <p>
* Title: 通用工具类
* </p>
* <p>
* Description: 常用工具的集合,用来处理常见问题,比如中文乱码的方法等。
* </p>
* <p>
* Copyright: Copyright (c) 2003
* </p>
* <p>
* Company: Towery
* </p>
*
* @author WangPinHeng
* @version 1.0
*/
public class Tools {
public Tools() {
//
}

     /**
* 字符串替换,将 source 中的 oldString 全部换成 newString
*
* @param source
*             源字符串
* @param oldString
*             老的字符串
* @param newString
*             新的字符串
* @return 替换后的字符串
*/
private static String Replace(String source, String oldString,
String newString) {
StringBuffer output = new StringBuffer();

         int lengthOfSource = source.length(); // 源字符串长度
int lengthOfOld = oldString.length(); // 老字符串长度

         int posStart = 0; // 开始搜索位置
int pos; // 搜索到老字符串的位置

         while ((pos = source.indexOf(oldString, posStart)) >= 0) {
output.append(source.substring(posStart, pos));

             output.append(newString);
posStart = pos + lengthOfOld;
}

         if (posStart < lengthOfSource) {
output.append(source.substring(posStart));
}

         return output.toString();
}

     /**
* 转换SQL中的特殊符号,比如将单引号"'"替换为"''",以免产生SQLException
*
* @param sqlstr
*             原SQL
* @return 处理后的SQL
*/
public static String toSql(String sqlstr) {
String strsql = sqlstr;
if (strsql == null) {
return "";
}
strsql = Replace(strsql, "'", "''");
return strsql;
}

     /**
* 将ISO8859_1编码的字符串转化为GB2312编码的字符串,主要用来处理中文显示乱码的问题
*
* @param ISO8859_1str
*             通过ISO8859_1编码的字符串
* @return 通过GB2312编码的字符串
*/
public String GBString(String ISO8859_1str) {
if (ISO8859_1str == null) {
return "";
} else {
try {
return new String(ISO8859_1str.getBytes("ISO8859_1"), "GB2312");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

     /**
* 将ISO8859_1编码的字符串转化为GB2312编码的字符串,主要用来处理中文显示乱码的问题
*
* @param ISO8859_1str
*             通过ISO8859_1编码的字符串
* @return 通过GB2312编码的字符串
*/
public static String GB2312FromISO8859_1(String ISO8859_1str) {
if (ISO8859_1str == null) {
return "";
} else {
try {
return new String(ISO8859_1str.getBytes("ISO8859_1"), "GB2312");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

     public String trim1(String str) {
String str1 = "";

         if (str.substring(0, 1).equals("?")) {
str1 = str.substring(1, str.length());
System.out.println("str1=" + str1);
} else {
str1 = str;
}

         return str1.trim();
}

     public String dateformat(String str) {
String day = str.substring(0, 2);
String month = str.substring(3, 5);
String year = str.substring(6, 10);
str = year + "-" + month + "-" + day;
return str;
}

     public String tenformat(String str) {
if (str.length() == 8) {
String year = str.substring(0, 4);
String month = "0" + str.substring(5, 6);
String day = "0" + str.substring(7, 8);
str = year + "-" + month + "-" + day;
} else if (str.length() == 9) {
if (str.substring(6, 7).equals("-")) {
str = str.substring(0, 5) + "0" + str.substring(5, 9);
} else {
str = str.substring(0, 8) + "0" + str.substring(8, 9);
}

         }
return str;
}

     /**
* 计算两个时间
*
* @param str
*             原时间,strsub,需减少的时间
* @return 计算后的时间
*/
public String subTime(String str, String strSub) {
String rsTime = "";
int hour = 0;
int sec = 0;
int secsub = 0;
str = trim(str);
strSub = trim(strSub);
if (str.length() == 5) {
hour = Integer.parseInt(str.substring(0, 2));

             sec = Integer.parseInt(str.substring(3, 5));

         } else if (str.length() == 4) {
hour = Integer.parseInt(str.substring(0, 1));

             sec = Integer.parseInt(str.substring(2, 4));

         }
if (trim(strSub).length() == 5) {
secsub = Integer.parseInt(strSub.substring(0, 2));

         } else if (trim(strSub).length() == 4) {
secsub = Integer.parseInt(strSub.substring(0, 1));

         }

         //int a = sec + secsub;
if (sec < secsub) {
//System.out.println("sub <");
String jstr = Integer.toString(sec + 60 - secsub);
String hstr = Integer.toString(hour - 1);
//System.out.println("jstr="+jstr);
//System.out.println("hstr="+hstr);
if (jstr.length() == 1) {
jstr = "0" + jstr;
}
if (hstr.length() == 1) {
hstr = "0" + hstr;
}
rsTime = hstr + ":" + jstr;

         } else if (sec == secsub) {
//System.out.println("sub =");
String strh = Integer.toString(hour);
//System.out.println("strh="+strh);
if (strh.length() == 1) {
strh = "0" + strh;
}
rsTime = strh + ":00";

         } else if (sec > secsub) {
//System.out.println("sub >");
String jstr = Integer.toString(sec - secsub);
//System.out.println("jstr="+jstr);
String hstr = Integer.toString(hour);
//System.out.println("hstr="+hstr);
if (jstr.length() == 1) {
jstr = "0" + jstr;
}
if (hstr.length() == 1) {
hstr = "0" + hstr;
}
rsTime = hstr + ":" + jstr;

         }
return rsTime;
}

     public String toSENDstr(String input) {
String r = input;
r = replace(r, "&", "");
r = replace(r, "/", "|");
r = replace(r, "\r", "");
r = replace(r, "\n", "");
r = replace(r, "'", "");
r = replace(r, " ", "");
return r;
}

     public String replace(String str, String strOld, String strNew) {
String r = str;
if (str != null && strOld != null && strNew != null) {
int idx = str.indexOf(strOld);
if (idx != -1) {
String strPre = "";
r = "";
String strSuf = str;
for (; idx != -1; idx = strSuf.indexOf(strOld)) {
strPre = strSuf.substring(0, idx);
strSuf = strSuf.substring(idx + strOld.length());
r = r + strPre + strNew;
}

                 r = r + strSuf;
}
}
return r;
}

     /**
* 计算两个时间相差的分钟数
*
* @param time1
*             string,time2,string
* @return string
*/
public String diffTime(String time1, String time2) {
String rsTime = "";
int hour = 0;
int hour2 = 0;
int sec = 0;
int sec2 = 0;
String str1 = trim(time1);
String str2 = trim(time2);
if (str1.length() == 5) {
hour = Integer.parseInt(str1.substring(0, 2));

             sec = Integer.parseInt(str1.substring(3, 5));

         } else if (str1.length() == 4) {
hour = Integer.parseInt(str1.substring(0, 1));

             sec = Integer.parseInt(str1.substring(2, 4));

         }
if (str2.length() == 5) {
hour2 = Integer.parseInt(str2.substring(0, 2));

             sec2 = Integer.parseInt(str2.substring(3, 5));

         } else if (str2.length() == 4) {
hour2 = Integer.parseInt(str2.substring(0, 1));

             sec2 = Integer.parseInt(str2.substring(2, 4));

         }

         //int a = sec + secsub;
if (sec < sec2) {
//System.out.println("sub <");
String jstr = Integer.toString(sec + 60 - sec2);
if (jstr.length() == 1) {
jstr = "0" + jstr;
}
if ((hour - 1) != hour2) {

                 String hstr = Integer.toString(hour - 1 - hour2);

                 if (hstr.length() == 1) {
hstr = "0" + hstr;
}
rsTime = hstr + ":" + jstr + ":00";
} else {
rsTime = jstr + ":00";
}
} else if (sec == sec2) {
//System.out.println("sub =");
if (hour != hour2) {

                 String strh = Integer.toString(hour - hour2);
//System.out.println("strh="+strh);
if (strh.length() == 1) {
strh = "0" + strh;
}
rsTime = strh + ":00" + ":00";
} else {
rsTime = "00:00";
}
} else if (sec > sec2) {
//System.out.println("sub >");
String jstr = Integer.toString(sec - sec2);
//System.out.println("jstr="+jstr);
if (jstr.length() == 1) {
jstr = "0" + jstr;
}
if (hour != hour2) {
String hstr = Integer.toString(hour - hour2);
//System.out.println("hstr="+hstr);
if (hstr.length() == 1) {
hstr = "0" + hstr;
}
rsTime = hstr + ":" + jstr + ":00";
} else {
rsTime = jstr + ":00";
}
}
return rsTime;
}

     /**
* 计算两个时间
*
* @param str
*             原时间,stradd,需增加的时间
* @return 计算后的时间
*/
public String addTime(String str, String stradd) {
String rsTime = "";
int hour = 0;
int sec = 0;
int secadd = 0;
int houradd = 0;
str = trim(str);
stradd = trim(stradd);
if (str.length() == 5) {
hour = Integer.parseInt(str.substring(0, 2));

             sec = Integer.parseInt(str.substring(3, 5));

         } else if (str.length() == 4) {
hour = Integer.parseInt(str.substring(0, 1));

             sec = Integer.parseInt(str.substring(2, 4));

         }
if (trim(stradd).length() == 5) {

             secadd = Integer.parseInt(stradd.substring(0, 2));

         } else if (trim(stradd).length() == 4) {
secadd = Integer.parseInt(stradd.substring(0, 1));

         } else if (trim(stradd).length() == 7) {
houradd = Integer.parseInt(stradd.substring(0, 1));
secadd = Integer.parseInt(stradd.substring(2, 4));
}
int a = sec + secadd;
if (a < 60) {
String stra = Integer.toString(a);
String strh = Integer.toString(hour + houradd);
if (stra.length() == 1) {
stra = "0" + stra;
}
if (strh.length() == 1) {
strh = "0" + strh;
} else if (Integer.parseInt(strh) > 24) {
int h = Integer.parseInt(strh) / 24;
strh = Integer.toString(h);
if (h < 10) {
strh = "0" + Integer.toString(h);
}
}
rsTime = strh + ":" + stra;

         } else if (a == 60) {
String strh = Integer.toString(hour + houradd + 1);
if (strh.length() == 1) {
strh = "0" + strh;
} else if (Integer.parseInt(strh) > 24) {
int h = Integer.parseInt(strh) / 24;
strh = Integer.toString(h);
if (h < 10) {
strh = "0" + Integer.toString(h);
}
}
rsTime = strh + ":00";

         } else if (a > 60) {
int i = a / 60;
int j = a % 60;
String strj = Integer.toString(j);

             if (strj.length() == 1) {
strj = "0" + strj;
}
String strh = Integer.toString(hour + houradd + i);
if (strh.length() == 1) {
strh = "0" + strh;
} else if (Integer.parseInt(strh) > 24) {
int h = Integer.parseInt(strh) / 24;
strh = Integer.toString(h);
if (h < 10) {
strh = "0" + Integer.toString(h);
}
}
rsTime = strh + ":" + strj;

             if (j == 0) {
rsTime = strh + ":00";

             }

         }
return rsTime;
}

JDBC调用存储过程:四种分类详解几实例(oracle) oracle,jdbc JDBC调用存储过程:四种分类详解及实例(Oracle)
create table TMP_MICHAEL
(
  USER_ID    VARCHAR2(20),
  USER_NAME  VARCHAR2(10),
  SALARY     NUMBER(8,2),
  OTHER_INFO VARCHAR2(100)
)

insert into TMP_MICHAEL (USER_ID, USER_NAME, SALARY, OTHER_INFO)
values ('michael', 'Michael', 5000, 'http://sjsky.iteye.com');
insert into TMP_MICHAEL (USER_ID, USER_NAME, SALARY, OTHER_INFO)
values ('zhangsan', '张三', 10000, null);
insert into TMP_MICHAEL (USER_ID, USER_NAME, SALARY, OTHER_INFO)
values ('aoi_sola', '苍井空', 99999.99, 'twitter account');
insert into TMP_MICHAEL (USER_ID, USER_NAME, SALARY, OTHER_INFO)
values ('李四', '李四', 2500, null);
验证码 html java自动生成验证码插件-kaptcha
<init-param>  
            <param-name>kaptcha.border</param-name>  
            <param-value>yes</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.border.color</param-name>  
            <param-value>105,179,90</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.textproducer.impl</param-name>  
            <param-value>com.randcode.ChineseText</param-value>  
        </init-param>  
  
        <init-param>  
            <param-name>kaptcha.textproducer.font.color</param-name>  
            <param-value>black</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.image.width</param-name>  
            <param-value>500</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.image.height</param-name>  
            <param-value>300</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.textproducer.font.size</param-name>  
            <param-value>90</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.session.key</param-name>  
            <param-value>code</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.textproducer.char.length</param-name>  
            <param-value>4</param-value>  
        </init-param>  
        <init-param>  
            <param-name>kaptcha.textproducer.font.names</param-name>  
            <param-value>宋体,楷体,微软雅黑</param-value>  
        </init-param> 
验证码 css, javascript, html 安全而且好看的验证码
	public function getAction() {
		$start = microtime(1);
		YL_Security_Secoder::entry();
		file_put_contents(dirname(__FILE__) . '/test.php', (microtime(1)-$start));
	}
ibatis中的iterator 标签的用法(一) java,ibatis,java IBATIS Iterate用法 初探
	/**
	 * 测试iterator
	 */
	public List<BabyDO> queryByIds(Map idsMap) throws SQLException {
		return client.queryForList("queryByIds", idsMap);
	}
DateUtil java, date 时间工具类,主要用于sql的时间段查询
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.DataFormatException;

import org.apache.commons.lang.time.DateUtils;
import com.pengsy.commons.stringutil.StringUtil;

/**
 * 该类主要服务于sql中基于时间的统计查询,在写sql的过程中建议不要使用to_char或者to_date等oracle函数
 * 这样不利用索引(除非你对to_char进行了类似索引的操作
 * ),比如:在表的logintime字段上建立了索引,但是在sql中使用to_char(logintime,'yyyy-MM-dd')
 * 作为检索条件的时候,数据库在logintime上建立的索引就没用了。在数据量很大的时候会影响检索的速度。
 *  提供如下方法: 
 *  1、获取当前时间(按天截取时间)
 *  2、根据指定时间提供天、周、旬、月、季度、年的开始时间,结束时间(时间格式采java.util.Date)
 *  3、给定字符串类型的startTime和endTime,工具类负责类型的转换(String转换成Date) 
 *  注意:
 *  1、在sql中使用开始时间和最后时间的时候,为了保证统计数据的正确性,
 *    sql按给出的例子组织:t.logintime >= startTime and t.loginTime <= entTime 
 *  2、时间的字符串格式采用 yyyy-MM-dd
 * 
 */

public final class DateUtil {

	private static SimpleDateFormat sDateFormat = new SimpleDateFormat(
			"yyyy-MM-dd");

	public static final int FIRSTTEN = 1 ;
	public static final int MIDTEN = 2;
	public static final int LASTTEN = 3;
	
	public static final int FIRSTQUARTER = 1;
	public static final int SECONDQUARTER = 2;
	public static final int THIRDQUARTER = 3;
	public static final int FORTHQUARTER = 4;
	
	private static Pattern pattern = Pattern
			.compile("^[1-9]\\d{3}-[01]?\\d-[0|1|2|3]?\\d$"); // 2010-12-22

	/**
	 * 获取当前系统时间按天截取的时间
	 * @return
	 */
	public static Date getSystemTranceDay(){
		return DateUtils.truncate(new Date(), Calendar.DATE);
	}
	
	/**
	 * 功能:根据指定时间获取当前天的开始和结束时间,以date数组返回
	 * 逻辑:
	 * 1、appointDate is null ,set default value sysdate
	 * 2、get date[]
	 * @param appointDate
	 * @return
	 */
	public static Date[] getDateArrByDay(Date appointDate){
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		//未完
		if(appointDate == null){
			appointDate = new Date();
		}
		stime = DateUtils.truncate(appointDate,Calendar.DATE);
		etime = DateUtils.addSeconds(DateUtils.truncate(DateUtils.addDays(appointDate, 1), Calendar.DATE),-1);
		
		date[0] = stime;
		date[1] = etime;
		return date;
	}
	
	/**
	 * 功能:根据指定时间获取当前星期的开始和结束时间,以date数组返回
	 * @param appointDate
	 * @return
	 */
	public static Date[] getDateArrByWeek(Date appointDate){
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		if(appointDate == null){
			appointDate = new Date();
		}
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(appointDate);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
		System.out.println(dayOfWeek);
		
		calendar.add(Calendar.DAY_OF_MONTH, -dayOfWeek+2);
		
		stime = DateUtils.truncate(calendar.getTime(), Calendar.DATE);
		calendar.add(Calendar.DAY_OF_MONTH, 7);
		etime = DateUtils.addSeconds(DateUtils.truncate(calendar.getTime(), Calendar.DATE), -1);
		
		date[0] = stime;
		date[1] = etime;
		
		return date;
	}
	
	/**
	 * 功能:根据指定的时间和上中下旬的其中一个,获取开始时间和结束时间
	 * @param appointDate
	 * @param appointIndex
	 * @return
	 */
	public static Date[] getDateArrByTenDays(Date appointDate,int appointIndex ){
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		if(appointDate == null){
			appointDate = new Date();
		}
		//init date
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(appointDate);
		int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		int maxDayOfMonth = calendar.getMaximum(Calendar.DAY_OF_MONTH);
		
		Date tempDate = DateUtils.truncate(DateUtils.addDays(appointDate, -dayOfMonth + 1), Calendar.DATE);
		
		if(appointIndex == FIRSTTEN){
			stime = tempDate;
			etime = DateUtils.addSeconds(DateUtils.addDays(stime, 10), -1);
		}
		
		if(appointIndex == MIDTEN){
			stime = DateUtils.addDays(tempDate, 10);
			etime = DateUtils.addSeconds(DateUtils.addDays(stime, 10), -1);
		}
		
		if(appointIndex == LASTTEN){
			stime = DateUtils.addDays(tempDate, 20);
			etime = DateUtils.addSeconds(DateUtils.addDays(tempDate, maxDayOfMonth), -1);
		}
		
		date[0] = stime;
		date[1] = etime; 
		return date;
	}
	
	/**
	 * 功能:根据指定时间获取相应月份的开始时间和结束时间
	 * @param appointDate
	 * @return
	 */
	public static Date[] getDateArrByMonth(Date appointDate){
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		if(appointDate == null){
			appointDate = new Date();
		}
		
		//init date
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(appointDate);
		int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		int maxDayOfMonth = calendar.getMaximum(Calendar.DAY_OF_MONTH);
		
		appointDate = DateUtils.truncate(appointDate, Calendar.DATE);
		
		stime = DateUtils.truncate(DateUtils.addDays(appointDate, -dayOfMonth+1), Calendar.DATE);
		etime = DateUtils.addSeconds(DateUtils.addDays(stime, maxDayOfMonth), -1);
		
		date[0] = stime;
		date[1] = etime;
		
		return date;
	}
	
	/**
	 * 功能:根据指定时间所在的当前年,获取指定季度的开始时间和结束时间
	 * @param appointDate 指定当前年
	 * @param appointIndex
	 * @return
	 * @throws IllegalArgumentException
	 */
	public static Date[] getDateArrByQuarter(Date appointDate,int appointIndex) throws IllegalArgumentException{
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		if(appointDate == null){
			appointDate = new Date();
		}
		int month = appointDate.getMonth();
		Date tempDate = DateUtils.truncate(appointDate, Calendar.YEAR);
		if(appointIndex == FIRSTQUARTER){
			stime = tempDate;
		}else if(appointIndex == SECONDQUARTER){
			stime = DateUtils.addMonths(tempDate, 3);
		}else if(appointIndex == THIRDQUARTER ){
			stime = DateUtils.addMonths(tempDate, 6);
		}else if(appointIndex == FORTHQUARTER){
			stime = DateUtils.addMonths(tempDate, 9);
		}
		etime = DateUtils.addSeconds(DateUtils.addMonths(stime, 3), -1);
		
		date[0] = stime;
		date[1] = etime;
		
		return date;
	}
	
	/**
	 * 功能:根据指定时间,获取年的开始时间和结束时间
	 * @param appointDate
	 * @return
	 */
	public static Date[] getDateArrByYear(Date appointDate){
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];
		if(appointDate == null){
			appointDate = new Date();
		}
		stime = DateUtils.truncate(appointDate, Calendar.YEAR);
		etime = DateUtils.addSeconds(DateUtils.addYears(stime, 1), -1);
		
		date[0] = stime;
		date[1] = etime;
		
		return date;
	}
	
	/**
	 * 逻辑: 1、检查startTime,endTime的有效性(是否为空,数据格式), 异常处理: 1、两个参数都为空,抛出空指针异常
	 * 2、数据格式不对,直接抛出 3、一个参数为空,另一个参数格式正确的情况下,为空的参数采用系统时间,为了保证startTime <=
	 * endTime,工具类会做适当的调整 2、转换 3、返回值是个Date[2]数组,date[0] 保存startTime值,date[1]
	 * 保存startTime值,其中startTime <= endTime
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static Date[] convertDateClass(String startTime, String endTime)
			throws NullPointerException, DataFormatException, ParseException {
		Date stime = null;
		Date etime = null;
		Date[] date = new Date[2];

		if (StringUtil.isEmpty(startTime) && StringUtil.isEmpty(endTime)) {
			throw new NullPointerException("两个参数不能同时为空");
		}

		if (StringUtil.isEmpty(startTime) && !StringUtil.isEmpty(endTime)) {
			// 先判断endTime格式是否正确
			Matcher matcher = pattern.matcher(endTime);
			if (matcher.matches()) {
				stime = DateUtils.truncate(new Date(), Calendar.DATE); // 当天的开始时间,比如:当前时间为2010-12-27 11:31:30 这里stime的时间是2010-12-27 0:0:0
				etime = DateUtils.truncate(sDateFormat.parse(endTime),Calendar.DATE);
			} else {
				throw new DataFormatException(
						"参数endTime的格式不正确!正确的格式 yyyy-MM-dd 比如:2010-12-12!");
			}
		}
		if (!StringUtil.isEmpty(startTime) && StringUtil.isEmpty(endTime)) {
			Matcher matcher = pattern.matcher(startTime);
			if (matcher.matches()) {
				// 提供转换
				etime = DateUtils.truncate(new Date(), Calendar.DATE); // 当天的开始时间,比如:当前时间为2010-12-27 11:31:30 这里stime的时间是2010-12-27 0:0:0
				stime = DateUtils.truncate(sDateFormat.parse(startTime),Calendar.DATE);
			} else {
				throw new DataFormatException(
						"参数startTime的格式不正确!正确的格式 yyyy-MM-dd 比如:2010-12-12!");
			}
		}

		if (!StringUtil.isEmpty(startTime) && !StringUtil.isEmpty(endTime)) {
			Matcher sMatcher = pattern.matcher(startTime);
			Matcher eMatcher = pattern.matcher(endTime);
			if (sMatcher.matches() && eMatcher.matches()) {

				stime = DateUtils.truncate(sDateFormat.parse(startTime),
						Calendar.DATE);
				etime = DateUtils.truncate(sDateFormat.parse(endTime),
						Calendar.DATE);

			} else {
				throw new DataFormatException(
						"请检查参数startTime、endTime的格式是否正确!正确的格式 yyyy-MM-dd 比如:2010-12-12!");
			}

		}

		if (!stime.before(etime)) {
			Date temp = stime;
			stime = etime;
			etime = temp;
			temp = null;
		}
		
		date[0] = stime;
		date[1] = etime;
		return date;
	}
}
文件上传下载 io 文件上传下载
public class FileUploadUtil
{
	/**
	 * 
	 * 将文件写入硬盘
	 * @param filePath
	 * @param is
	 * @param clazz this.getClass()
	 */
	public static void writeFile(String filePath, InputStream is,Class clazz)
	{
      String fullPath = clazz.getResource("").getPath(); 
      fullPath = fullPath.substring(0, fullPath.indexOf("/WEB-INF"));
      File f = createFileIfNotExist(fullPath+filePath);
      byte[] buffer = new byte[8192];
      OutputStream fos = null;
      int readByte = 0;
      try
      {
         fos = new FileOutputStream(f);
         while ((readByte = is.read(buffer, 0, 8192)) != -1)
         {
            fos.write(buffer, 0, readByte);
         }
         fos.flush();
      } catch (FileNotFoundException e)
      {
         e.printStackTrace();
      } catch (IOException e)
      {
         e.printStackTrace();
      } finally
      {
         try
         {
            if (is != null)
            {
               is.close();
               is = null;
            }
            if (fos != null)
            {
               fos.close();
               fos = null;
            }
            if (f != null)
            {
               f = null;
            }
         } catch (IOException e)
         {
            e.printStackTrace();
         }
      }
	}	
	
	/**
	 * 判断路径是否存在
	 * @param path
	 * @return
	 */
	public static File createFileIfNotExist(String path)
	{
      String [] filePathArray = path.split("\\\\|/");
      StringBuilder sbPath = new StringBuilder();
      File temp = null;
      int level = filePathArray.length;
      int cur = 0;
      for (String frag : filePathArray)
      {
         cur++;
         sbPath.append(frag).append(File.separator);
         temp = new File(sbPath.toString());
         if (!temp.exists())
         {
            if (cur < level)
            {
               temp.mkdir();
            }
            else
            {
               try
               {
                  temp.createNewFile();
               } catch (IOException e)
               {
                  e.printStackTrace();
               }
            }
         }
      }
      return temp;
	}
	
	/**
	 * 
	 * 读取文件
	 * @param fileName
	 * @param filePath  文件上下文后的相对路径
	 * @param clazz  this.getClass()
	 */
	public static void readFile(String fileName, String filePath, Class clazz, HttpServletResponse response)
	{
		OutputStream ut = null;  
		try {  
			// 读取文件并且设置相关参数  
			String fullPath = clazz.getResource("").getPath(); 
			fullPath = fullPath.substring(0, fullPath.indexOf("/WEB-INF"));
		    File file = new File(fullPath+filePath);  
		    fileName = new String(fileName.getBytes("gb2312"),"iso8859-1");//取消乱码  
		    byte[] buf = new byte[1024];  
		    int len = 0;  
		    BufferedInputStream br = null;  
		    response.reset();//保存临时文件  
		    response.setContentType("application/x-msdownload");  
		    response.setHeader("Content-Disposition","attachment; filename=" + fileName);  
			br = new BufferedInputStream(new FileInputStream(file));
			ut = response.getOutputStream();  
			while((len=br.read(buf))!=-1){  
			   ut.write(buf, 0, len);  
			}
		} catch (Exception e) {  
			e.printStackTrace();  
		} finally{
			try {
				ut.flush();
				ut.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}	
}
集成valuelist配置详解及源码扩展 valuelist 集成valueList配置详解及源码扩展
	xml内容如下:
	<?xml version="1.0" encoding="UTF-8"?>
	<beans xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
		xmlns:context="http://www.springframework.org/schema/context"
		xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
		xmlns:aop="http://www.springframework.org/schema/aop"
		xsi:schemaLocation="
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">

		<bean id="valueListHelper" class="net.mlw.vlh.web.mvc.ValueListHandlerHelper">
			<property name="valueListHandler">
				<ref bean="valueListHandler"/>
			</property>
		</bean>
		
		<bean id="valueListHandler" class="net.mlw.vlh.DefaultValueListHandlerImpl">
		 <property name="config.adapters">
		      <map>
			 <entry key="testAdapter">
			  <bean class="net.mlw.vlh.adapter.jdbc.dynabean.DefaultDynaBeanAdapter">
			    <property name="dataSource"><ref bean="dataSource"/></property>
			    <property name="useName"><value>false</value></property>
			    <property name="showSql"><value>true</value></property>
			    <property name="defaultNumberPerPage"><value>10</value></property>	
					<property name="defaultSortDirection"><value>desc</value></property>	
					<property name="defaultSortColumn" ><value>name</value></property>
			    <property name="adapterType"><value>2</value></property>
			    <property name="sql">
			      <value>
					select id from test
			      </value>
			    </property>
			  </bean>
			</entry>
		      </map>
		 </property>
		</bean>
	</beans>
小脚本中数字格式化 js, format number javascript js format number 数字格式化
function _format(pattern,num,z){
	var j =	pattern.length >= num.length ? pattern.length : num.length ;
	var p = pattern.split("");
	var n = num.split("");
	var bool = true,nn = "";
	for(var i=0;i<j;i++){
		var x = n[n.length-j+i];
		var y = p[p.length-j+i];
		if( z == 0){
			if(bool){
				if( ( x && y && (x != "0" || y == "0")) || ( x && x != "0" && !y ) || ( y && y == "0" && !x )  ){
					nn += x ? x : "0";
					bool = false;
				}	
			} else {
				nn +=  x ? x : "0" ;
			}
		} else {
			if( y && ( y == "0" || ( y == "#" && x ) ))
				nn += x ? x : "0" ;								
		}
	}
	return nn;
}
function _formatNumber(numChar,pattern){
	var patterns = pattern.split(".");
	var	numChars = numChar.split(".");
	var z = patterns[0].indexOf(",") == -1 ? -1 : patterns[0].length - patterns[0].indexOf(",") ;
	var num1 = _format(patterns[0].replace(","),numChars[0],0);
	var num2 = _format(	patterns[1]?patterns[1].split('').reverse().join(''):"", numChars[1]?numChars[1].split('').reverse().join(''):"",1);
	num1 =	num1.split("").reverse().join('');
	var reCat = eval("/[0-9]{" + (z-1) + "," + (z-1) + "}/gi");
	var arrdata = z > -1 ? num1.match(reCat) : undefined ;
	if( arrdata && arrdata.length > 0 ){
		var w =	num1.replace(arrdata.join(''),'');
		num1 = arrdata.join(',') + ( w == "" ? "" : "," ) + w ;
	}
	num1 = num1.split("").reverse().join("");
	return (num1 == "" ? "0" : num1) + (num2 != "" ? "." + num2.split("").reverse().join('') : "" ); 					
} 
function formatNumber(num,opt){
	var reCat = /[0#,.]{1,}/gi;
	var zeroExc = opt.zeroExc == undefined ? true : opt.zeroExc ;
	var pattern = opt.pattern.match(reCat)[0];
	var numChar = num.toString();
	return !(zeroExc && numChar == 0) ? opt.pattern.replace(pattern,_formatNumber(numChar,pattern)) : opt.pattern.replace(pattern,"0");
}
Global site tag (gtag.js) - Google Analytics