首页>代码>S2SH(spring+struts2+hibernate) 开发java学生信息管理网站源码下载>/JavaWebProject/src/com/student2where/action/EntrepreneurStudentAction.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.EntrepreneurStudentDAO; import com.student2where.domain.EntrepreneurStudent; import com.student2where.dao.ProfessionInfoDAO; import com.student2where.domain.ProfessionInfo; import com.student2where.dao.YearInfoDAO; import com.student2where.domain.YearInfo; import com.student2where.dao.ProvinceInfoDAO; import com.student2where.domain.ProvinceInfo; @Controller @Scope("prototype") public class EntrepreneurStudentAction 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 String nianji; public void setNianji(String nianji) { this.nianji = nianji; } public String getNianji() { return this.nianji; } /*界面层需要查询的属性: 年份*/ private YearInfo yearObj; public void setYearObj(YearInfo yearObj) { this.yearObj = yearObj; } public YearInfo getYearObj() { return this.yearObj; } /*界面层需要查询的属性: 省份*/ private ProvinceInfo provinceObj; public void setProvinceObj(ProvinceInfo provinceObj) { this.provinceObj = provinceObj; } public ProvinceInfo getProvinceObj() { return this.provinceObj; } /*界面层需要查询的属性: 创业名称*/ private String chuangyemingcheng; public void setChuangyemingcheng(String chuangyemingcheng) { this.chuangyemingcheng = chuangyemingcheng; } public String getChuangyemingcheng() { return this.chuangyemingcheng; } /*当前第几页*/ 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 EntrepreneurStudentDAO entrepreneurStudentDAO; @Resource ProfessionInfoDAO professionInfoDAO; @Resource YearInfoDAO yearInfoDAO; @Resource ProvinceInfoDAO provinceInfoDAO; /*待操作的EntrepreneurStudent对象*/ private EntrepreneurStudent entrepreneurStudent; public void setEntrepreneurStudent(EntrepreneurStudent entrepreneurStudent) { this.entrepreneurStudent = entrepreneurStudent; } public EntrepreneurStudent getEntrepreneurStudent() { return this.entrepreneurStudent; } /*跳转到添加EntrepreneurStudent视图*/ 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); /*查询所有的ProvinceInfo信息*/ List<ProvinceInfo> provinceInfoList = provinceInfoDAO.QueryAllProvinceInfoInfo(); ctx.put("provinceInfoList", provinceInfoList); return "add_view"; } /*添加EntrepreneurStudent信息*/ @SuppressWarnings("deprecation") public String AddEntrepreneurStudent() { ActionContext ctx = ActionContext.getContext(); try { if(true) { ProfessionInfo professionObj = professionInfoDAO.GetProfessionInfoByProfessionId(entrepreneurStudent.getProfessionObj().getProfessionId()); entrepreneurStudent.setProfessionObj(professionObj); } if(true) { YearInfo yearObj = yearInfoDAO.GetYearInfoByYearId(entrepreneurStudent.getYearObj().getYearId()); entrepreneurStudent.setYearObj(yearObj); } if(true) { ProvinceInfo provinceObj = provinceInfoDAO.GetProvinceInfoByProvinceId(entrepreneurStudent.getProvinceObj().getProvinceId()); entrepreneurStudent.setProvinceObj(provinceObj); } entrepreneurStudentDAO.AddEntrepreneurStudent(entrepreneurStudent); ctx.put("message", java.net.URLEncoder.encode("EntrepreneurStudent添加成功!")); return "add_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("EntrepreneurStudent添加失败!")); return "error"; } } /*查询EntrepreneurStudent信息*/ public String QueryEntrepreneurStudent() { if(currentPage == 0) currentPage = 1; if(studentName == null) studentName = ""; if(nianji == null) nianji = ""; if(chuangyemingcheng == null) chuangyemingcheng = ""; List<EntrepreneurStudent> entrepreneurStudentList = entrepreneurStudentDAO.QueryEntrepreneurStudentInfo(studentName, professionObj, nianji, yearObj, provinceObj, chuangyemingcheng, currentPage); /*计算总的页数和总的记录数*/ entrepreneurStudentDAO.CalculateTotalPageAndRecordNumber(studentName, professionObj, nianji, yearObj, provinceObj, chuangyemingcheng); /*获取到总的页码数目*/ totalPage = entrepreneurStudentDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = entrepreneurStudentDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("entrepreneurStudentList", entrepreneurStudentList); 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("nianji", nianji); ctx.put("yearObj", yearObj); List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo(); ctx.put("yearInfoList", yearInfoList); ctx.put("provinceObj", provinceObj); List<ProvinceInfo> provinceInfoList = provinceInfoDAO.QueryAllProvinceInfoInfo(); ctx.put("provinceInfoList", provinceInfoList); ctx.put("chuangyemingcheng", chuangyemingcheng); return "query_view"; } /*后台导出到excel*/ public String QueryEntrepreneurStudentOutputToExcel() { if(studentName == null) studentName = ""; if(nianji == null) nianji = ""; if(chuangyemingcheng == null) chuangyemingcheng = ""; List<EntrepreneurStudent> entrepreneurStudentList = entrepreneurStudentDAO.QueryEntrepreneurStudentInfo(studentName,professionObj,nianji,yearObj,provinceObj,chuangyemingcheng); ExportExcelUtil ex = new ExportExcelUtil(); String title = "EntrepreneurStudent信息记录"; String[] headers = { "姓名","性别","专业","年级","年份","省份","创业名称"}; List<String[]> dataset = new ArrayList<String[]>(); for(int i=0;i<entrepreneurStudentList.size();i++) { EntrepreneurStudent entrepreneurStudent = entrepreneurStudentList.get(i); dataset.add(new String[]{entrepreneurStudent.getStudentName(),entrepreneurStudent.getSex(),entrepreneurStudent.getProfessionObj().getProfessionName(), entrepreneurStudent.getNianji(),entrepreneurStudent.getYearObj().getYearName(), entrepreneurStudent.getProvinceObj().getProvinceName(), entrepreneurStudent.getChuangyemingcheng()}); } /* 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="+"EntrepreneurStudent.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; } /*前台查询EntrepreneurStudent信息*/ public String FrontQueryEntrepreneurStudent() { if(currentPage == 0) currentPage = 1; if(studentName == null) studentName = ""; if(nianji == null) nianji = ""; if(chuangyemingcheng == null) chuangyemingcheng = ""; List<EntrepreneurStudent> entrepreneurStudentList = entrepreneurStudentDAO.QueryEntrepreneurStudentInfo(studentName, professionObj, nianji, yearObj, provinceObj, chuangyemingcheng, currentPage); /*计算总的页数和总的记录数*/ entrepreneurStudentDAO.CalculateTotalPageAndRecordNumber(studentName, professionObj, nianji, yearObj, provinceObj, chuangyemingcheng); /*获取到总的页码数目*/ totalPage = entrepreneurStudentDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = entrepreneurStudentDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("entrepreneurStudentList", entrepreneurStudentList); 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("nianji", nianji); ctx.put("yearObj", yearObj); List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo(); ctx.put("yearInfoList", yearInfoList); ctx.put("provinceObj", provinceObj); List<ProvinceInfo> provinceInfoList = provinceInfoDAO.QueryAllProvinceInfoInfo(); ctx.put("provinceInfoList", provinceInfoList); ctx.put("chuangyemingcheng", chuangyemingcheng); return "front_query_view"; } /*查询要修改的EntrepreneurStudent信息*/ public String ModifyEntrepreneurStudentQuery() { ActionContext ctx = ActionContext.getContext(); /*根据主键studentId获取EntrepreneurStudent对象*/ EntrepreneurStudent entrepreneurStudent = entrepreneurStudentDAO.GetEntrepreneurStudentByStudentId(studentId); List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo(); ctx.put("professionInfoList", professionInfoList); List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo(); ctx.put("yearInfoList", yearInfoList); List<ProvinceInfo> provinceInfoList = provinceInfoDAO.QueryAllProvinceInfoInfo(); ctx.put("provinceInfoList", provinceInfoList); ctx.put("entrepreneurStudent", entrepreneurStudent); return "modify_view"; } /*查询要修改的EntrepreneurStudent信息*/ public String FrontShowEntrepreneurStudentQuery() { ActionContext ctx = ActionContext.getContext(); /*根据主键studentId获取EntrepreneurStudent对象*/ EntrepreneurStudent entrepreneurStudent = entrepreneurStudentDAO.GetEntrepreneurStudentByStudentId(studentId); List<ProfessionInfo> professionInfoList = professionInfoDAO.QueryAllProfessionInfoInfo(); ctx.put("professionInfoList", professionInfoList); List<YearInfo> yearInfoList = yearInfoDAO.QueryAllYearInfoInfo(); ctx.put("yearInfoList", yearInfoList); List<ProvinceInfo> provinceInfoList = provinceInfoDAO.QueryAllProvinceInfoInfo(); ctx.put("provinceInfoList", provinceInfoList); ctx.put("entrepreneurStudent", entrepreneurStudent); return "front_show_view"; } /*更新修改EntrepreneurStudent信息*/ public String ModifyEntrepreneurStudent() { ActionContext ctx = ActionContext.getContext(); try { if(true) { ProfessionInfo professionObj = professionInfoDAO.GetProfessionInfoByProfessionId(entrepreneurStudent.getProfessionObj().getProfessionId()); entrepreneurStudent.setProfessionObj(professionObj); } if(true) { YearInfo yearObj = yearInfoDAO.GetYearInfoByYearId(entrepreneurStudent.getYearObj().getYearId()); entrepreneurStudent.setYearObj(yearObj); } if(true) { ProvinceInfo provinceObj = provinceInfoDAO.GetProvinceInfoByProvinceId(entrepreneurStudent.getProvinceObj().getProvinceId()); entrepreneurStudent.setProvinceObj(provinceObj); } entrepreneurStudentDAO.UpdateEntrepreneurStudent(entrepreneurStudent); ctx.put("message", java.net.URLEncoder.encode("EntrepreneurStudent信息更新成功!")); return "modify_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("EntrepreneurStudent信息更新失败!")); return "error"; } } /*删除EntrepreneurStudent信息*/ public String DeleteEntrepreneurStudent() { ActionContext ctx = ActionContext.getContext(); try { entrepreneurStudentDAO.DeleteEntrepreneurStudent(studentId); ctx.put("message", java.net.URLEncoder.encode("EntrepreneurStudent删除成功!")); return "delete_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("EntrepreneurStudent删除失败!")); return "error"; } } }
最近下载更多
wanglinddad LV55
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日