代码改变世界

代码解析

2017-03-24 16:57  高小小小帅  阅读(572)  评论(0编辑  收藏  举报

1.避免对参数直接赋值 2.关键字大写

 

 

 

 

private ActionForward bookCaseAdd(ActionMapping mapping, ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response){
bookcaseform bookCaseForm = (bookcaseform) form;
System.out.println("servlet:"+request.getParameter("name"));
bookCaseForm.setName(bookCaseForm.getName());
int a=bookCaseDAO.insert(bookCaseForm);
int ret=0;
if(a==0){
request.setAttribute("error","书架信息添加失败!");
return mapping.findForward("error");
}else if(a==2){
request.setAttribute("error","该书架信息已经添加!");
return mapping.findForward("error");
}else{
return mapping.findForward("bookcaseAdd");
}
}
/***********************查询全部书架信息**************************/
private ActionForward bookCaseQuery(ActionMapping mapping, ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response){
String str=null;
request.setAttribute("bookcase",bookCaseDAO.query(str));
return mapping.findForward("bookcaseQuery");
}
/***********************查询修改书架信息**************************/
private ActionForward bookCaseModifyQuery(ActionMapping mapping, ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response){
bookcaseform bookCaseForm=(bookcaseform)form;
bookCaseForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookCaseQueryif",bookCaseDAO.queryM(bookCaseForm));
return mapping.findForward("bookCaseQueryModify");
}
/***********************修改书架信息**************************/
private ActionForward bookCaseModify(ActionMapping mapping, ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response){
bookcaseform bookCaseForm=(bookcaseform)form;
bookCaseForm.setName(request.getParameter("name"));
int ret=bookCaseDAO.update(bookCaseForm);
if(ret==0){
request.setAttribute("error","修改书架信息失败!");
return mapping.findForward("error");
}else{
return mapping.findForward("bookCaseModify");
}
}
/***********************删除书架信息**************************/
private ActionForward bookCaseDel(ActionMapping mapping, ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response
){
bookcaseform bookCaseForm=(bookcaseform)form;
bookCaseForm.setId(Integer.valueOf(request.getParameter("ID")));
int ret=bookCaseDAO.delete(bookCaseForm);
if(ret==0){
request.setAttribute("error","删除书架信息失败!");
return mapping.findForward("error");
}else{
return mapping.findForward("bookCaseDel");
}
}


参数的书写采用驼峰式

bookcaseform bookCaseForm = (bookcaseform) form;//应改为,BookCaseForm
System.out.println("servlet:"+request.getParameter("name"));
bookCaseForm.setName(bookCaseForm.getName());//应改为,BookCaseForm