首页 > 代码库 > 代码解析
代码解析
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
代码解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。