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;
    
  • 相关阅读:
    php中常用的字符串函数,大全了
    php写的验证码实现方法
    简单的php做的一个验证码生成方案
    ActiveMQ+SpringMVC+Maven应用示例
    zookeeper简单操作
    zookeeper基本概念及原理
    zookeeper 事务日志与快照日志
    activeMQ安装与测试
    activeMQ "HelloWorld"实现
    JMS基本概念
  • 原文地址:https://www.cnblogs.com/huitudou/p/6612103.html
Copyright © 2011-2022 走看看