检查清单:
1.避免对参数直接赋值
2.关键字大写
3.不要魔法数
代码:
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
参数尽量用相应的单词表示:
int a=bookCaseDAO.insert(bookCaseForm);
避免对参数直接赋值
int ret=0;