HR代码3

来源:互联网 发布:锥套轮图纸数据 编辑:程序博客网 时间:2024/06/01 15:24

package org.better.hr.comm;

package org.better.hr.comm;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

public class CopyBean {
 
 /**
  * 复制成员变量的值
  * @param dest 目标对象
  * @param orig 源对象
  * @throws ClassNotFoundException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  * @throws NoSuchMethodException
  */
 public static void copyProperties(Object dest,Object orig) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
 {
  String field_name;
  Class clz = orig.getClass();   //获得源对象的类
  Field[] sup = clz.getSuperclass().getDeclaredFields();  //获得源类的父类的所有属性
  
  for(int i=0;i<sup.length;i++)
  {
   field_name = sup[i].getName();  //得到源对象所有属性的名字
   String value = BeanUtils.getProperty(orig, field_name);  //得到源对象属性的值
   if(!sup[i].getType().getName().equals("java.util.Date") && value != null && !value.equals("") && !value.equals("0"))
   {
    BeanUtils.setProperty(dest, field_name, value);  //将源对象的属性值赋到目标对象中
   }
   //System.out.println(field_name + ":  " + BeanUtils.getProperty(dest, field_name));
  }
  
  Field[] sub = clz.getDeclaredFields();  //获得源对象的所有属性
  for(int i=0;i<sub.length;i++)
  {
   field_name = sub[i].getName();
   String value = BeanUtils.getProperty(orig, field_name);
   if(!sub[i].getType().getName().equals("java.util.Date") && value != null && !value.equals("") && !value.equals("0"))
   {
    BeanUtils.setProperty(dest, field_name, value);
   }
   //System.out.println(field_name + ":  " + BeanUtils.getProperty(dest, field_name));
  }
 }
}

 

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

 

package org.better.hr.comm;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.struts.upload.FormFile;

public class Load {
 
 
 public static String upload(FormFile file,String filepath)
 {
  FileOutputStream fileOutput;
            try {
                fileOutput = new FileOutputStream(filepath+file.getFileName());
                fileOutput.write(file.getFileData());
                fileOutput.flush();
                fileOutput.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        return file.getFileName();
 }
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

package org.better.hr.comm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

 

public class Util {
 private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 private static SimpleDateFormat tf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 private static SimpleDateFormat sf = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

 /**
  * 检验传入的字符串是否为空
  * @param s 被检验的字符串
  * @return 如果字符串为空对象或空字符串,则返回true
  */
 public static boolean isNullOrBlank(final String s) {
  if (s == null) {
   return true;
  }
  if (s.trim().equals("")) {
   return true;
  }
  return false;
 }
 
 /**
  * 检验传入的数字是否为空
  * @param s 传入的短整型数字
  * @return 如果为空对象或值为-1则为真
  */
 public static boolean isNullOrBlank(final Short s) {
  if (s == null || s.intValue() == -1) {
   return true;
  }
  return false;
 }
 
 /**
  * 将字符串转换成日期类型
  * @param date 传入的字符串
  * @return 转换成的日期值
  */
 public static Date parseDate(String date)
 {
  Date ret = null;
  if(date != null && date != "")
  {
   try {
    ret = df.parse(date);
   } catch (ParseException e) {
    ret = null;
   }
  }
  return ret;
 }
 
 /**
  * 将日期类型转换成"yyyy-MM-dd"字符串
  * @param date 传入的日期值
  * @return 字符串类型的日期值
  */
 public static String formatDate(Date date)
 {
  String ret = "";
  try {
   ret = df.format(date);
  }
  catch(Exception e)
  {
   ret = "";
  }
  return ret;
 }
 
 /**
  * 将日期类型转换成"yyyy-MM-dd hh:mm:ss"字符串
  * @param date
  * @return
  */
 public static String formatTime(Date date)
 {
  String ret = "";
  try {
   ret = tf.format(date);
  }
  catch(Exception e)
  {
   ret = "";
  }
  return ret;
 }
 
 /**
  * 将日期类型转换成"yyyy_MM_dd_hh_mm_ss"字符串
  * @param date
  * @return
  */
 public static String formatDateTime(Date date)
 {
  String ret = "";
  try {
   ret = sf.format(date);
  }
  catch(Exception e)
  {
   ret = "";
  }
  return ret;
 }
 
 /**
  * 将类似"编号/名称"的字符串以"/"进行拆分
  * @param idandname
  * @return 字符串数组
  */
 public static String[] splitIdAndName(String idandname)
 {
  String[] obj = idandname.split("/");
  return obj;
 }
 
 /**
  * 将路径以"\\"符进行拆分
  * @param path
  * @return
  */
 public static String[] splitPath(String path)
 {
  String[] obj = null;
  if(path != null && !path.equals(""))
   obj = path.split("\\\\");
  return obj;
 }
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

 

包:package org.better.hr.comm.export;

package org.better.hr.comm.export;

import java.io.File;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.dom.DocumentImpl;

public class Excel
{
public static void createDoc(String[] tagName,List tagValue,String filename)
{
    try {
        Document doc = new DocumentImpl();  //创建xml文档
        Element root = doc.createElement("table");  //创建根节点
       
        for(int i=0; i<tagValue.size(); i++)
        {
         Element child = createElement(doc,tagName,(Object[])tagValue.get(i));
         root.appendChild(child);
        }
          
        doc.appendChild(root);
        save(doc,filename);
    } catch(Exception e){
        e.printStackTrace();
    }
}

/**
 * 创建节点
 * @param doc
 * @param tagName 节点名称
 * @param tagValue 节点值
 * @return
 */
public static Element createElement(Document doc,String[] tagName,Object[] tagValue)
{
 Element rootNode = doc.createElement("humanFile");
 
 for(int i=0; i<tagName.length; i++)
 {
  Element tagNode = doc.createElement(tagName[i]);
  Text textNode = doc.createTextNode((null==tagValue[i])?"":tagValue[i].toString());
  tagNode.appendChild(textNode);
  rootNode.appendChild(tagNode);
 }
    return rootNode;
}

/**
 * 保存xml文件
 * @param doc xml文档
 * @param xmlFileName 文件名
 */
public static void save(Document doc,String xmlFileName){
    try{
        TransformerFactory tfactory = TransformerFactory.newInstance();
        Transformer transformer = tfactory.newTransformer();
        transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING,"GB2312");
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File(xmlFileName));
        transformer.transform(source, result);
    }catch(Exception e){
        e.printStackTrace();
    }
}
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

 

包:package org.better.hr.comm.page;

/**
 *
 */
package org.better.hr.comm.page;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hailong.liu
 */
public class PageResult {
 private List list = new ArrayList(); //查询结果
 private int pageNo = 1; //实际页号
 private int pageSize = 3; //每页记录数
 private int recTotal = 0; //总记录数
 
 public List getList() {
  return list;
 }
 public void setList(List list) {
  this.list = list;
 }
 public int getPageNo() {
  return pageNo;
 }
 public void setPageNo(int pageNo) {
  this.pageNo = pageNo;
 }
 public int getPageSize() {
  return (0==pageSize)?10:pageSize;
 }
 public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }
 public int getRecTotal() {
  return recTotal;
 }
 public void setRecTotal(int recTotal) {
  this.recTotal = recTotal;
 }
 public int getPageTotal() {
  int ret = (this.getRecTotal() - 1) / this.getPageSize() + 1;
  ret = (ret<1)?1:ret;
  return ret;
 }
 public int getFirstRec()
 {
  int ret = (this.getPageNo()-1) * this.getPageSize();// + 1;
  ret = (ret < 1)?0:ret;
  return ret;
 }
 
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

package org.better.hr.comm.page;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
 * 分页显示的辅助程序
 * 用作跳页
 */
public class updownPage extends TagSupport {
   /**
  *
  */
 private static final long serialVersionUID = 1L;
private String file="";
   int num=0;
   public String getFile() {
     return file;
   }

   public void setFile(String file) {
     this.file=file;
   }

   public int getNum() {
     return num;
   }

   public void setNum(int num) {
     this.num=num;
   }

   public int doStartTag() throws JspException {
  int intPage=1;
  int PageCount=1;
  if(pageContext.getAttribute("intPage")!=null) {
  intPage=Integer.parseInt((String)pageContext.getAttribute("intPage"));
  pageContext.removeAttribute("intPage");
  }
  if(pageContext.getAttribute("PageCount")!=null) {
  PageCount=Integer.parseInt((String)pageContext.getAttribute("PageCount"));
  pageContext.removeAttribute("PageCount");
  }
   try {
      pageContext.getOut().print("<p>&nbsp;&nbsp;总数:"+num+"例 &nbsp;&nbsp;&nbsp;");
   if (intPage> 1) {
         pageContext.getOut().print("<A href=\""+file+"?page="+
                                    new Integer(intPage-1).toString()+
                                    "\"><font color=\"#000000\">上一页</font></A> &nbsp;&nbsp;&nbsp;");
    }
         pageContext.getOut().print("当前第 "+intPage+" 页  &nbsp;&nbsp;&nbsp;");
   if (intPage < PageCount) {
         pageContext.getOut().print("<A href=\""+file+"?page="+new Integer(intPage+1).toString()+
                                    "\"><font color=\"#000000\">下一页</font></A> &nbsp;&nbsp;&nbsp;");
    }
         pageContext.getOut().print("共 "+PageCount+" 页  &nbsp;&nbsp;&nbsp;"+
                                    "跳到第 <input name=page type=text class=input1 size=1> 页&nbsp;&nbsp;"+
                                    "<input type=image src=\"images/go.bmp\" width=18 height=18 border=0>");
   } catch(Exception ioException) {
    System.err.println("Exception thrown ");
    throw new JspException(ioException);
   }
   return SKIP_BODY;
  }
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、