📄 u04studentaction.java
字号:
package cn.hope.mana.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.LookupDispatchAction;
import cn.hope.mana.bo.U04StudentBO;
import cn.hope.mana.pojo.SClass;
import cn.hope.mana.pojo.Student;
import cn.hope.mana.pojo.U04CommonListVO;
public class U04StudentAction extends LookupDispatchAction{
Logger log = Logger.getLogger(U04StudentAction.class.getName());
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.sele","sele");
map.put("button.add","add");
map.put("button.search","search");
map.put("button.endorse","endorse");
return map;
}
private U04StudentBO u04studentBO = new U04StudentBO();
//查询方法
public ActionForward search(ActionMapping mapping,ActionForm form
,HttpServletRequest request,HttpServletResponse response)throws Exception{
ActionMessages errors = new ActionMessages();
DynaActionForm studentForm = (DynaActionForm) form;
Student st = new Student();
U04CommonListVO cl_vo = new U04CommonListVO();
List list = null;
SClass sclass = new SClass();
int start = 0;//起始记录
try{
st = (Student)studentForm.get("student");
if(StringUtils.isNotEmpty(request.getParameter("start"))){//判断是否为空
start = Integer.parseInt(request.getParameter("start"));
}
list = u04studentBO.U04ClassSearchAll(sclass);
cl_vo = u04studentBO.serachAll(st,start);//调用bo中的查询方法返回一个分页实体
request.getSession().setAttribute("studentList",cl_vo);//把返回的实体set到session
request.getSession().setAttribute("classList",list);//所有班级集合
return mapping.findForward("success");
}catch(Exception e){
//log.error(e);
e.printStackTrace();
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.u04exception"));
return mapping.findForward("errorPage");
}
}
//添加方法
public ActionForward add(ActionMapping mapping,ActionForm form
,HttpServletRequest request,HttpServletResponse response)throws Exception{
System.out.println("addaddadddddddddddd");
return mapping.findForward("success");
}
//执行方法
public ActionForward endorse(ActionMapping mapping,ActionForm form
,HttpServletRequest request,HttpServletResponse response)throws Exception{
ActionMessages errors = new ActionMessages();
DynaActionForm studentForm = (DynaActionForm) form;
Student st = new Student();
try{
Integer seleid = (Integer)studentForm.get("seleId");//删除,报表,邮件群发,选择下拉列表id
String[] u04CheckStr = (String[])studentForm.get("u04CheckStr");//复选框数组
if(seleid!=null){ //判断下拉列表不为null
if(u04CheckStr.length>0){
int i = seleid.intValue();
if(i>=0){ //下拉列表的值必须大于等于0
if(i==1){//对下拉列表进行判断
for(int j = 0; j < u04CheckStr.length;j++){
String s = u04CheckStr[j];
st = u04studentBO.searchByKey(s,false);//查询指定id的实体
st.setFlag("1");//更改指定记录值
u04studentBO.modify(st); //调用修改方法
}
return mapping.findForward("delet");
}
}
}
}
return mapping.findForward("success");
}catch(Exception e){
log.error(e);
e.printStackTrace();
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.u04exception"));
return mapping.findForward("errorPage");
}
}
//按条件查询方法
public ActionForward sele(ActionMapping mapping,ActionForm form
,HttpServletRequest request,HttpServletResponse response)throws Exception{
ActionMessages errors = new ActionMessages();
DynaActionForm studentForm = (DynaActionForm) form;
U04CommonListVO cl_vo = new U04CommonListVO();
int start = 0;//起始记录
String name="";
boolean eq;
boolean isname;
try{
if(StringUtils.isNotEmpty(request.getParameter("start"))){//判断是否为空
start = Integer.parseInt(request.getParameter("start"));
}
name = (String) studentForm.get("nameText");
isname=u04studentBO.uName(name);
if(isname){
Boolean isEq = (Boolean) studentForm.get("isEq");
if(isEq==null){
eq = false;
cl_vo = u04studentBO.serachName(name,start,eq);
int gc = cl_vo.getCount();
request.getSession().setAttribute("studentList",cl_vo);
if(gc>0){
return mapping.findForward("success");
}
else{
return mapping.findForward("nouser");
}
}
else{
eq = isEq.booleanValue();
cl_vo = u04studentBO.serachName(name,start,eq);
request.getSession().setAttribute("studentList",cl_vo);
int gc = cl_vo.getCount();
if(gc>0){
return mapping.findForward("success");
}
else{
return mapping.findForward("nouser");
}
}
}
else{
Integer cid = (Integer) studentForm.get("seleClassid");
int classid = cid.intValue();
if(classid==0){
return mapping.findForward("success");
}
else{
cl_vo = u04studentBO.classSerachAll(classid,start);
request.getSession().setAttribute("studentList",cl_vo);
return mapping.findForward("success");
}
}
}catch(Exception e){
log.error(e);
e.printStackTrace();
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.u04exception"));
return mapping.findForward("errorPage");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -