zoukankan      html  css  js  c++  java
  • Friend's Code Review

    检查清单:

    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;
    
  • 相关阅读:
    [POI2007]山峰和山谷Grz
    [POI2007]驾驶考试egz
    [POI2007]立方体大作战tet
    BZOJ1085 [SCOI2005]骑士精神
    BZOJ1975 [Sdoi2010]魔法猪学院
    codeforces754D Fedor and coupons
    UOJ79 一般图最大匹配
    BZOJ3944 Sum
    BZOJ3434 [Wc2014]时空穿梭
    UOJ58 【WC2013】糖果公园
  • 原文地址:https://www.cnblogs.com/huitudou/p/6612103.html
Copyright © 2011-2022 走看看