首页>代码>S2SH(spring+struts2+hibernate) 开发java学生信息管理网站源码下载>/JavaWebProject/src/com/student2where/action/GetJobStudentAction.java
package com.student2where.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.UUID;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.student2where.utils.ExportExcelUtil;
import com.student2where.dao.GetJobStudentDAO;
import com.student2where.domain.GetJobStudent;
import com.student2where.dao.ProfessionInfoDAO;
import com.student2where.domain.ProfessionInfo;
import com.student2where.dao.YearInfoDAO;
import com.student2where.domain.YearInfo;
@Controller @Scope("prototype")
public class GetJobStudentAction extends ActionSupport {

    /*界面层需要查询的属性: 姓名*/
    private String studentName;
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }
    public String getStudentName() {
        return this.studentName;
    }

    /*界面层需要查询的属性: 专业*/
    private ProfessionInfo professionObj;
    public void setProfessionObj(ProfessionInfo professionObj) {
        this.professionObj = professionObj;
    }
    public ProfessionInfo getProfessionObj() {
        return this.professionObj;
    }

    /*界面层需要查询的属性: 年份*/
    private YearInfo yearObj;
    public void setYearObj(YearInfo yearObj) {
        this.yearObj = yearObj;
    }
    public YearInfo getYearObj() {
        return this.yearObj;
    }

    /*界面层需要查询的属性: 地区*/
    private String area;
    public void setArea(String area) {
        this.area = area;
    }
    public String getArea() {
        return this.area;
    }

    /*界面层需要查询的属性: 就业单位*/
    private String jiuyedanwei;
    public void setJiuyedanwei(String jiuyedanwei) {
        this.jiuyedanwei = jiuyedanwei;
    }
    public String getJiuyedanwei() {
        return this.jiuyedanwei;
    }

    /*当前第几页*/
    private int currentPage;
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getCurrentPage() {
        return currentPage;
    }

    /*一共多少页*/
    private int totalPage;
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public int getTotalPage() {
        return totalPage;
    }

    private int studentId;
    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }
    public int getStudentId() {
        return studentId;
    }

    /*当前查询的总记录数目*/
    private int recordNumber;
    public void setRecordNumber(int recordNumber) {
        this.recordNumber = recordNumber;
    }
    public int getRecordNumber() {
        return recordNumber;
    }

    /*业务层对象*/
    @Resource GetJobStudentDAO getJobStudentDAO;

    @Resource ProfessionInfoDAO professionInfoDAO;
    @Resource YearInfoDAO yearInfoDAO;
    /*待操作的GetJobStudent对象*/
    private GetJobStudent getJobStudent;
    public void setGetJobStudent(GetJobStudent getJobStudent) {
        this.getJobStudent = getJobStudent;
    }
    public GetJobStudent getGetJobStudent() {
        return this.getJobStudent;
    }

    /*跳转到添加GetJobStudent视图*/
    public String AddView() {
        ActionContext ctx = ActionContext.getContext();
        /*查询所有的ProfessionInfo信息*/
        List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo();
        ctx.put("professionInfoList", professionInfoList);
        /*查询所有的YearInfo信息*/
        List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo();
        ctx.put("yearInfoList", yearInfoList);
        return "add_view";
    }

    /*添加GetJobStudent信息*/
    @SuppressWarnings("deprecation")
    public String AddGetJobStudent() {
        ActionContext ctx = ActionContext.getContext();
        try {
            if(true) {
            ProfessionInfo professionObj = professionInfoDAO.GetProfessionInfoByProfessionId(getJobStudent.getProfessionObj().getProfessionId());
            getJobStudent.setProfessionObj(professionObj);
            }
            if(true) {
            YearInfo yearObj = yearInfoDAO.GetYearInfoByYearId(getJobStudent.getYearObj().getYearId());
            getJobStudent.setYearObj(yearObj);
            }
            getJobStudentDAO.AddGetJobStudent(getJobStudent);
            ctx.put("message",  java.net.URLEncoder.encode("GetJobStudent添加成功!"));
            return "add_success";
        } catch (Exception e) {
            e.printStackTrace();
            ctx.put("error",  java.net.URLEncoder.encode("GetJobStudent添加失败!"));
            return "error";
        }
    }

    /*查询GetJobStudent信息*/
    public String QueryGetJobStudent() {
        if(currentPage == 0) currentPage = 1;
        if(studentName == null) studentName = "";
        if(area == null) area = "";
        if(jiuyedanwei == null) jiuyedanwei = "";
        List<GetJobStudent> getJobStudentList = getJobStudentDAO.QueryGetJobStudentInfo(studentName, professionObj, yearObj, area, jiuyedanwei, currentPage);
        /*计算总的页数和总的记录数*/
        getJobStudentDAO.CalculateTotalPageAndRecordNumber(studentName, professionObj, yearObj, area, jiuyedanwei);
        /*获取到总的页码数目*/
        totalPage = getJobStudentDAO.getTotalPage();
        /*当前查询条件下总记录数*/
        recordNumber = getJobStudentDAO.getRecordNumber();
        ActionContext ctx = ActionContext.getContext();
        ctx.put("getJobStudentList",  getJobStudentList);
        ctx.put("totalPage", totalPage);
        ctx.put("recordNumber", recordNumber);
        ctx.put("currentPage", currentPage);
        ctx.put("studentName", studentName);
        ctx.put("professionObj", professionObj);
        List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo();
        ctx.put("professionInfoList", professionInfoList);
        ctx.put("yearObj", yearObj);
        List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo();
        ctx.put("yearInfoList", yearInfoList);
        ctx.put("area", area);
        ctx.put("jiuyedanwei", jiuyedanwei);
        return "query_view";
    }

    /*后台导出到excel*/
    public String QueryGetJobStudentOutputToExcel() { 
        if(studentName == null) studentName = "";
        if(area == null) area = "";
        if(jiuyedanwei == null) jiuyedanwei = "";
        List<GetJobStudent> getJobStudentList = getJobStudentDAO.QueryGetJobStudentInfo(studentName,professionObj,yearObj,area,jiuyedanwei);
        ExportExcelUtil ex = new ExportExcelUtil();
        String title = "GetJobStudent信息记录"; 
        String[] headers = { "姓名","性别","专业","年级","年份","地区","就业单位"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<getJobStudentList.size();i++) {
        	GetJobStudent getJobStudent = getJobStudentList.get(i); 
        	dataset.add(new String[]{getJobStudent.getStudentName(),getJobStudent.getStudentSex(),getJobStudent.getProfessionObj().getProfessionName(),
getJobStudent.getNianji(),getJobStudent.getYearObj().getYearName(),
getJobStudent.getArea(),getJobStudent.getJiuyedanwei()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		HttpServletResponse response = null;//创建一个HttpServletResponse对象 
		OutputStream out = null;//创建一个输出流对象 
		try { 
			response = ServletActionContext.getResponse();//初始化HttpServletResponse对象 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"GetJobStudent.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = ServletActionContext.getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
		return null;
    }
    /*前台查询GetJobStudent信息*/
    public String FrontQueryGetJobStudent() {
        if(currentPage == 0) currentPage = 1;
        if(studentName == null) studentName = "";
        if(area == null) area = "";
        if(jiuyedanwei == null) jiuyedanwei = "";
        List<GetJobStudent> getJobStudentList = getJobStudentDAO.QueryGetJobStudentInfo(studentName, professionObj, yearObj, area, jiuyedanwei, currentPage);
        /*计算总的页数和总的记录数*/
        getJobStudentDAO.CalculateTotalPageAndRecordNumber(studentName, professionObj, yearObj, area, jiuyedanwei);
        /*获取到总的页码数目*/
        totalPage = getJobStudentDAO.getTotalPage();
        /*当前查询条件下总记录数*/
        recordNumber = getJobStudentDAO.getRecordNumber();
        ActionContext ctx = ActionContext.getContext();
        ctx.put("getJobStudentList",  getJobStudentList);
        ctx.put("totalPage", totalPage);
        ctx.put("recordNumber", recordNumber);
        ctx.put("currentPage", currentPage);
        ctx.put("studentName", studentName);
        ctx.put("professionObj", professionObj);
        List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo();
        ctx.put("professionInfoList", professionInfoList);
        ctx.put("yearObj", yearObj);
        List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo();
        ctx.put("yearInfoList", yearInfoList);
        ctx.put("area", area);
        ctx.put("jiuyedanwei", jiuyedanwei);
        return "front_query_view";
    }

    /*查询要修改的GetJobStudent信息*/
    public String ModifyGetJobStudentQuery() {
        ActionContext ctx = ActionContext.getContext();
        /*根据主键studentId获取GetJobStudent对象*/
        GetJobStudent getJobStudent = getJobStudentDAO.GetGetJobStudentByStudentId(studentId);

        List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo();
        ctx.put("professionInfoList", professionInfoList);
        List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo();
        ctx.put("yearInfoList", yearInfoList);
        ctx.put("getJobStudent",  getJobStudent);
        return "modify_view";
    }

    /*查询要修改的GetJobStudent信息*/
    public String FrontShowGetJobStudentQuery() {
        ActionContext ctx = ActionContext.getContext();
        /*根据主键studentId获取GetJobStudent对象*/
        GetJobStudent getJobStudent = getJobStudentDAO.GetGetJobStudentByStudentId(studentId);

        List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo();
        ctx.put("professionInfoList", professionInfoList);
        List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo();
        ctx.put("yearInfoList", yearInfoList);
        ctx.put("getJobStudent",  getJobStudent);
        return "front_show_view";
    }

    /*更新修改GetJobStudent信息*/
    public String ModifyGetJobStudent() {
        ActionContext ctx = ActionContext.getContext();
        try {
            if(true) {
            ProfessionInfo professionObj = professionInfoDAO.GetProfessionInfoByProfessionId(getJobStudent.getProfessionObj().getProfessionId());
            getJobStudent.setProfessionObj(professionObj);
            }
            if(true) {
            YearInfo yearObj = yearInfoDAO.GetYearInfoByYearId(getJobStudent.getYearObj().getYearId());
            getJobStudent.setYearObj(yearObj);
            }
            getJobStudentDAO.UpdateGetJobStudent(getJobStudent);
            ctx.put("message",  java.net.URLEncoder.encode("GetJobStudent信息更新成功!"));
            return "modify_success";
        } catch (Exception e) {
            e.printStackTrace();
            ctx.put("error",  java.net.URLEncoder.encode("GetJobStudent信息更新失败!"));
            return "error";
       }
   }

    /*删除GetJobStudent信息*/
    public String DeleteGetJobStudent() {
        ActionContext ctx = ActionContext.getContext();
        try { 
            getJobStudentDAO.DeleteGetJobStudent(studentId);
            ctx.put("message",  java.net.URLEncoder.encode("GetJobStudent删除成功!"));
            return "delete_success";
        } catch (Exception e) { 
            e.printStackTrace();
            ctx.put("error",  java.net.URLEncoder.encode("GetJobStudent删除失败!"));
            return "error";
        }
    }

}
最近下载更多
wanglinddad  LV54 2022年3月5日
tx1121  LV14 2021年5月6日
and123456  LV11 2021年4月20日
liangge2115  LV27 2020年11月27日
张青峰  LV10 2020年9月9日
Alan Turing  LV14 2020年7月9日
862960632  LV14 2020年7月6日
17797226326  LV3 2020年5月16日
pt11100  LV9 2020年5月7日
诗若灯清  LV8 2019年12月25日
最近浏览更多
磊哥哥哥哥  LV13 2023年12月26日
haotzy  LV3 2023年10月5日
卢本伟不开挂  LV4 2023年9月3日
uni-code_0123  LV1 2023年8月8日
zhizhiz 2023年7月2日
暂无贡献等级
li951753  LV2 2023年6月19日
王华伟  LV19 2023年4月27日
喝喝XYZo  LV2 2023年4月17日
彩色天空  LV5 2023年4月11日
Tayirjan  LV11 2022年12月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友