stuaction.java
字号:
package action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Student;
import model.StudentForm;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class StuAction extends BaseAction {
//添加学生记录
public ActionForward ins(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo=(StudentForm)form;
// System.out.println(stu_vo.getId());
Student stu_po=new Student();
BeanUtils.copyProperties(stu_po, stu_vo);
getService().getBaseDAO().createObj(stu_po);
return list(mapping, form, request, response);
}
//删除学生记录
public ActionForward del(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// StudentForm stu_vo = (StudentForm) form;
// Student stu_po=getService().getBaseDAO().findById(stu_vo.getId());
// getService().getBaseDAO().delObject(stu_po);
String[] idd=request.getParameterValues("chk");
// System.out.println(idd[0]);
getService().getBaseDAO().del("delete from Student where id in (:idd)",idd);
return list(mapping, form, request, response);
}
//取得要修改的学生资料,并把页面导向detail.sjp
public ActionForward getMdfInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo = (StudentForm) form;
// System.out.println(request.getParameter("id"));
Student stu_po = (Student)getService().getBaseDAO().findById(Student.class,request.getParameter("id"));
BeanUtils.copyProperties(stu_vo, stu_po);
// stu_po.setNewsContent("a\ns");
System.out.println(stu_po.getNewsContent());
request.setAttribute("stuForm", stu_po);
return mapping.findForward("upd");
}
//修改学生记录
public ActionForward upd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo = (StudentForm) form;
Student stu_po = new Student();
BeanUtils.copyProperties(stu_po, stu_vo);
getService().getBaseDAO().mdfObj(stu_po);
return list(mapping, form, request, response);
}
//取得学生列表,并发送到stu_list.jsp
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// if(request.getSession().getAttribute("uname")==null) return mapping.findForward("login");
String op = request.getParameter("op");
String newsType = request.getParameter("newsType");
String cx = " where newsType= " + newsType;
String titleNews=request.getParameter("titleNews");
String beginTime=request.getParameter("beginTime");
String endTime=request.getParameter("endTime");
if(titleNews==null) titleNews = "";
else titleNews = titleNews.trim();
if(beginTime==null) beginTime = "";
if(endTime==null) endTime = "";
request.setAttribute("titleNews", titleNews);
request.setAttribute("beginTime", beginTime);
request.setAttribute("endTime", endTime);
// java.util.Date d=new java.util.date("");
if(op!=null){
cx+=" and newsTitle like '%"+titleNews+"%'";
if(!beginTime.equals("")) cx+=" and newsDate >= '"+beginTime+"'";
if(!endTime.equals("")) cx+=" and newsDate <= '"+endTime+" 23:59:59'";
// System.out.println(s);
}
else{
if(request.getParameter("cx")!=null) cx = request.getParameter("cx");
}
String hql="from Student " + cx + " order by newsDate desc";
int perPage = 5;
int rowCount = getService().getBaseDAO().getCount("select count(id) from Student" + cx);
int pageCount = (rowCount % perPage == 0 ? rowCount / perPage : rowCount / perPage+1);
int Page = 1;
if(op==null && request.getParameter("page")!=null) Page = Integer.parseInt(request.getParameter("page"));
if(Page > pageCount) Page = pageCount;
if(Page <= 0) Page = 1;
int start = (Page - 1) * perPage;
List temp = getService().getBaseDAO().getList(hql,perPage,start);
// List list = new ArrayList(temp.size());
// int end = start+perPage;
// if(end>temp.size()) end=temp.size();
// for (int i = start; i < end; i++) {
// Student stu_po = (Student) temp.get(i);
// StudentForm stu_vo = new StudentForm();
// BeanUtils.copyProperties(stu_vo, stu_po);
// list.add(stu_vo);
// }
request.setAttribute("list", temp);
request.setAttribute("page", Page+"");
request.setAttribute("rowCount", rowCount+"");
request.setAttribute("pageCount",pageCount+"");
request.setAttribute("cx",cx);
request.setAttribute("newsType",newsType);
return mapping.findForward("list");
// ActionForward actForward = mapping.findForward("list");
// String path = actForward.getPath();
// path += "?page=2";
// return new ActionForward(actForward.getName(),path,true);
}
//添加学生记录
public ActionForward ins_k(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo=(StudentForm)form;
// System.out.println(stu_vo.getId());
Student stu_po=new Student();
BeanUtils.copyProperties(stu_po, stu_vo);
getService().getBaseDAO().createObj(stu_po);
return list_k(mapping, form, request, response);
}
//删除学生记录
public ActionForward del_k(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// StudentForm stu_vo = (StudentForm) form;
// Student stu_po=getService().getBaseDAO().findById(stu_vo.getId());
// getService().getBaseDAO().delObject(stu_po);
String[] idd=request.getParameterValues("chk");
// System.out.println(idd[0]);
getService().getBaseDAO().del("delete from Student where id in (:idd)",idd);
return list_k(mapping, form, request, response);
}
//取得要修改的学生资料,并把页面导向detail.sjp
public ActionForward getMdfInfo_k(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo = (StudentForm) form;
// System.out.println(request.getParameter("id"));
Student stu_po = (Student)getService().getBaseDAO().findById(Student.class,request.getParameter("id"));
BeanUtils.copyProperties(stu_vo, stu_po);
// stu_po.setNewsContent("a\ns");
System.out.println(stu_po.getNewsContent());
request.setAttribute("stuForm", stu_po);
return mapping.findForward("upd_k");
}
//修改学生记录
public ActionForward upd_k(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo = (StudentForm) form;
Student stu_po = new Student();
BeanUtils.copyProperties(stu_po, stu_vo);
getService().getBaseDAO().mdfObj(stu_po);
return list_k(mapping, form, request, response);
}
//取得学生列表,并发送到stu_list.jsp
public ActionForward list_k(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// if(request.getSession().getAttribute("uname")==null) return mapping.findForward("login");
String op = request.getParameter("op");
String newsType = request.getParameter("newsType");
String cx = " where newsType= " + newsType;
String titleNews=request.getParameter("titleNews");
String beginTime=request.getParameter("beginTime");
String endTime=request.getParameter("endTime");
if(titleNews==null) titleNews = "";
else titleNews = titleNews.trim();
if(beginTime==null) beginTime = "";
if(endTime==null) endTime = "";
request.setAttribute("titleNews", titleNews);
request.setAttribute("beginTime", beginTime);
request.setAttribute("endTime", endTime);
// java.util.Date d=new java.util.date("");
if(op!=null){
cx+=" and newsTitle like '%"+titleNews+"%'";
if(!beginTime.equals("")) cx+=" and newsDate >= '"+beginTime+"'";
if(!endTime.equals("")) cx+=" and newsDate <= '"+endTime+" 23:59:59'";
// System.out.println(s);
}
else{
if(request.getParameter("cx")!=null) cx = request.getParameter("cx");
}
String hql="from Student " + cx + " order by newsDate desc";
int perPage = 5;
int rowCount = getService().getBaseDAO().getCount("select count(id) from Student" + cx);
int pageCount = (rowCount % perPage == 0 ? rowCount / perPage : rowCount / perPage+1);
int Page = 1;
if(op==null && request.getParameter("page")!=null) Page = Integer.parseInt(request.getParameter("page"));
if(Page > pageCount) Page = pageCount;
if(Page <= 0) Page = 1;
int start = (Page - 1) * perPage;
List temp = getService().getBaseDAO().getList(hql,perPage,start);
// List list = new ArrayList(temp.size());
// int end = start+perPage;
// if(end>temp.size()) end=temp.size();
// for (int i = start; i < end; i++) {
// Student stu_po = (Student) temp.get(i);
// StudentForm stu_vo = new StudentForm();
// BeanUtils.copyProperties(stu_vo, stu_po);
// list.add(stu_vo);
// }
request.setAttribute("list", temp);
request.setAttribute("page", Page+"");
request.setAttribute("rowCount", rowCount+"");
request.setAttribute("pageCount",pageCount+"");
request.setAttribute("cx",cx);
request.setAttribute("newsType",newsType);
return mapping.findForward("list_k");
// ActionForward actForward = mapping.findForward("list");
// String path = actForward.getPath();
// path += "?page=2";
// return new ActionForward(actForward.getName(),path,true);
}
public ActionForward kjhm(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// System.out.println(request.getParameter("id"));
// Student stu_po = (Student)getService().getBaseDAO().getList("from Student where newsType=11 order by newsDate desc",1,0).get(0);
// BeanUtils.copyProperties(stu_vo, stu_po);
// stu_po.setNewsContent("a\ns");
// System.out.println(stu_po.getNewsContent());
request.setAttribute("k2", (Student)getService().getBaseDAO().getList("from Student where newsType=12 order by newsDate desc",1,0).get(0));
request.setAttribute("k3", (Student)getService().getBaseDAO().getList("from Student where newsType=13 order by newsDate desc",1,0).get(0));
request.setAttribute("k4", (Student)getService().getBaseDAO().getList("from Student where newsType=14 order by newsDate desc",1,0).get(0));
return mapping.findForward("kjhm");
}
public ActionForward kjhm_q(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String newsType = request.getParameter("newsType");
String newsTitle = request.getParameter("newsTitle");
String hql="from Student where newsType=" + newsType;
request.setAttribute("kk", getService().getBaseDAO().getList(hql + " order by newsDate desc",99,0));
if(newsTitle==null) hql += " order by newsDate desc";
else hql += " and newsTitle='" + newsTitle + "'";
request.setAttribute("k", (Student)getService().getBaseDAO().getList(hql,1,0).get(0));
return mapping.findForward("kjhm_q");
}
public ActionForward list1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String newsType = request.getParameter("newsType");
String hql="from Student where newsType="+newsType+" order by newsDate desc";
int perPage = 20;
int rowCount = getService().getBaseDAO().getCount("select count(id) from Student where newsType="+newsType);
int pageCount = (rowCount % perPage == 0 ? rowCount / perPage : rowCount / perPage+1);
int Page = 1;
if(request.getParameter("page")!=null) Page = Integer.parseInt(request.getParameter("page"));
if(Page > pageCount) Page = pageCount;
if(Page <= 0) Page = 1;
int start = (Page - 1) * perPage;
List temp = getService().getBaseDAO().getList(hql,perPage,start);
request.setAttribute("list", temp);
request.setAttribute("page", Page+"");
request.setAttribute("rowCount", rowCount+"");
request.setAttribute("pageCount",pageCount+"");
request.setAttribute("newsType",newsType);
return mapping.findForward(newsType.toString());
}
public ActionForward getMdfInfo1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentForm stu_vo = (StudentForm) form;
// System.out.println(request.getParameter("id"));
Student stu_po = (Student)getService().getBaseDAO().findById(Student.class,request.getParameter("id"));
BeanUtils.copyProperties(stu_vo, stu_po);
request.setAttribute("stuForm", stu_vo);
request.setAttribute("newsType",stu_po.getNewsType()+"");
return mapping.findForward("detail");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -