package com.shuangyulin.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;
import org.apache.struts2.ServletActionContext;
import java.util.List;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.shuangyulin.dao.Student_QQ287307421DAO;
import com.shuangyulin.domain.Student_QQ287307421;
import com.shuangyulin.dao.ClassInfoDAO;
import com.shuangyulin.domain.ClassInfo;
import com.shuangyulin.test.TestUtil;
public class Student_QQ287307421Action extends ActionSupport {
/*图片字段studentPhoto参数接收*/
private File studentPhotoFile;
private String studentPhotoFileFileName;
private String studentPhotoFileContentType;
public File getStudentPhotoFile() {
return studentPhotoFile;
}
public void setStudentPhotoFile(File studentPhotoFile) {
this.studentPhotoFile = studentPhotoFile;
}
public String getStudentPhotoFileFileName() {
return studentPhotoFileFileName;
}
public void setStudentPhotoFileFileName(String studentPhotoFileFileName) {
this.studentPhotoFileFileName = studentPhotoFileFileName;
}
public String getStudentPhotoFileContentType() {
return studentPhotoFileContentType;
}
public void setStudentPhotoFileContentType(String studentPhotoFileContentType) {
this.studentPhotoFileContentType = studentPhotoFileContentType;
}
/*界面层需要查询的属性: 学号*/
private String studentNumber;
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
public String getStudentNumber() {
return this.studentNumber;
}
/*界面层需要查询的属性: 姓名*/
private String studentName;
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentName() {
return this.studentName;
}
/*界面层需要查询的属性: 所在班级*/
private ClassInfo studentClassNumber;
public void setStudentClassNumber(ClassInfo studentClassNumber) {
this.studentClassNumber = studentClassNumber;
}
public ClassInfo getStudentClassNumber() {
return this.studentClassNumber;
}
/*界面层需要查询的属性: 出生日期*/
private String studentBirthday;
public void setStudentBirthday(String studentBirthday) {
this.studentBirthday = studentBirthday;
}
public String getStudentBirthday() {
return this.studentBirthday;
}
/*当前第几页*/
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 recordNumber;
public void setRecordNumber(int recordNumber) {
this.recordNumber = recordNumber;
}
public int getRecordNumber() {
return recordNumber;
}
/*业务层对象*/
Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO();
/*待操作的Student_QQ287307421对象*/
private Student_QQ287307421 student_QQ287307421;
public void setStudent_QQ287307421(Student_QQ287307421 student_QQ287307421) {
this.student_QQ287307421 = student_QQ287307421;
}
public Student_QQ287307421 getStudent_QQ287307421() {
return this.student_QQ287307421;
}
/*跳转到添加Student_QQ287307421视图*/
public String AddView() {
ActionContext ctx = ActionContext.getContext();
/*查询所有的ClassInfo信息*/
ClassInfoDAO classInfoDAO = new ClassInfoDAO();
List<ClassInfo> classInfoList = classInfoDAO.QueryAllClassInfoInfo();
ctx.put("classInfoList", classInfoList);
return "add_view";
}
/*添加Student_QQ287307421信息*/
@SuppressWarnings("deprecation")
public String AddStudent_QQ287307421() {
ActionContext ctx = ActionContext.getContext();
/*验证学号是否已经存在*/
String studentNumber = student_QQ287307421.getStudentNumber();
Student_QQ287307421 db_student_QQ287307421 = student_QQ287307421DAO.GetStudent_QQ287307421ByStudentNumber(studentNumber);
if(null != db_student_QQ287307421) {
ctx.put("error", java.net.URLEncoder.encode("该学号已经存在!"));
return "error";
}
try {
if(true) {
ClassInfoDAO classInfoDAO = new ClassInfoDAO();
ClassInfo studentClassNumber = classInfoDAO.GetClassInfoByClassNumber(student_QQ287307421.getStudentClassNumber().getClassNumber());
student_QQ287307421.setStudentClassNumber(studentClassNumber);
}
String path = ServletActionContext.getServletContext().getRealPath("/upload");
/*处理图片上传*/
String studentPhotoFileName = "";
if(studentPhotoFile != null) {
InputStream is = new FileInputStream(studentPhotoFile);
String fileContentType = this.getStudentPhotoFileContentType();
if(fileContentType.equals("image/jpeg") || fileContentType.equals("image/pjpeg"))
studentPhotoFileName = UUID.randomUUID().toString() + ".jpg";
else if(fileContentType.equals("image/gif"))
studentPhotoFileName = UUID.randomUUID().toString() + ".gif";
else {
ctx.put("error", java.net.URLEncoder.encode("上传图片格式不正确!"));
return "error";
}
File file = new File(path, studentPhotoFileName);
OutputStream os = new FileOutputStream(file);
byte[] b = new byte[1024];
int bs = 0;
while ((bs = is.read(b)) > 0) {
os.write(b, 0, bs);
}
is.close();
os.close();
}
if(studentPhotoFile != null)
student_QQ287307421.setStudentPhoto("upload/" + studentPhotoFileName);
else
student_QQ287307421.setStudentPhoto("upload/NoImage.jpg");
student_QQ287307421DAO.AddStudent_QQ287307421(student_QQ287307421);
ctx.put("message", java.net.URLEncoder.encode("Student_QQ287307421添加成功!"));
return "add_success";
} catch (Exception e) {
e.printStackTrace();
ctx.put("error", java.net.URLEncoder.encode("Student_QQ287307421添加失败!"));
return "error";
}
}
/*查询Student_QQ287307421信息*/
public String QueryStudent_QQ287307421() {
if(currentPage == 0) currentPage = 1;
if(studentNumber == null) studentNumber = "";
if(studentName == null) studentName = "";
if(studentBirthday == null) studentBirthday = "";
List<Student_QQ287307421> student_QQ287307421List = student_QQ287307421DAO.QueryStudent_QQ287307421Info(studentNumber, studentName, studentClassNumber, studentBirthday, currentPage);
/*计算总的页数和总的记录数*/
student_QQ287307421DAO.CalculateTotalPageAndRecordNumber(studentNumber, studentName, studentClassNumber, studentBirthday);
/*获取到总的页码数目*/
totalPage = student_QQ287307421DAO.getTotalPage();
/*当前查询条件下总记录数*/
recordNumber = student_QQ287307421DAO.getRecordNumber();
ActionContext ctx = ActionContext.getContext();
ctx.put("student_QQ287307421List", student_QQ287307421List);
ctx.put("totalPage", totalPage);
ctx.put("recordNumber", recordNumber);
ctx.put("currentPage", currentPage);
ctx.put("studentNumber", studentNumber);
ctx.put("studentName", studentNa
syf_888
- 粉丝: 16
- 资源: 117
最新资源
- 粒子滤波在电力负荷预测中的应用:Python代码复现与详细算法解析,关于粒子滤波在电力负荷预测中的应用 python源代码,代码按照高水平文章复现,有详细说明,保证正确 在线预测电力负荷,在贝叶斯框
- 电力价格风险管理:MATLAB源码复现与波动性分析:从布莱克-斯科尔斯模型到极端价格应对策略探索,能源价格风险管理matlab源代码,代码按照高水平文章复现,保证正确 电力价格的波动性远远大于其他通常
- libgpg-error-1.12-3.el7.x64-86.rpm.tar.gz
- libgpg-error-devel-1.12-3.el7.x64-86.rpm.tar.gz
- 电力市场中生产者战略招标:凸规划方法与matlab源代码实践高效解决方案,电力市场中生产者的战略招标:一种凸松弛方法matlab 源代码,代码按照高水平文章复现,保证正确 电力市场中的战略投标问题在电
- libgphoto2-2.5.15-3.el7.x64-86.rpm.tar.gz
- FMC ADC12D2000RF模块:高端数据采集,含开发包与源代码,国内稀缺,珍贵转让,FMC ADC12D2000RF 模块,忍痛出射频直接采集FMC ADC模块,模块基于Ti公司高端ADC12
- libgpod-0.8.2-12.el7.x64-86.rpm.tar.gz
- FPGA PCI代码模块详解:完整实现与详尽注释,FPGA pci代码,模块完整,注释完整 ,FPGA; PCI代码; 模块完整; 注释完整;,"FPGA PCI代码全集:模块完备,详尽注释的编程宝
- libgpod-devel-0.8.2-12.el7.x64-86.rpm.tar.gz
- 欧姆龙CP1e与三台变频器Modbus 485通讯实现启停与频率给定控制,欧姆龙CP1e与三台欧姆龙变频器走485modbus通讯程 启停,频率给定控制 ,核心关键词:欧姆龙CP1e; 欧姆龙变频器
- libgpod-doc-0.8.2-12.el7.x64-86.rpm.tar.gz
- libgs-9.25-5.el7.x64-86.rpm.tar.gz
- 西门子S7-200 Smart与施耐德ATV变频器Modbus通讯:实现稳定控制及自动化启停与状态监测功能,接线与设置指南 ,西门子200smart与施耐德ATV变频器modbus通讯 西门子s7-2
- libgs-devel-9.25-5.el7.x64-86.rpm.tar.gz
- "上市公司TI平台高低压软启动控制源码揭秘:联系获取源码及厂家图,低压软启动方案同时呈现",上市公司的高压软启动控制源码,源码,需要的联系,平台TI,厂家见图,也有低压软起动的方案, ,上市公司; 高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈