用的是struts2 框架JSP传参数进来,例如 ×××.jsp?id=1根据id 进行业务方法调用就出现了很多switch  要如何改?页面的展示是查询数据库出来的LIST

解决方案 »

  1.   


    switch (id.intValue()) { case 0:
                调用业务方法
    break; case 1:
                 调用业务方法 break;
    case 11:
    break;

    case 13: break;
    case 14:

    break;
    case 15: break;
    case 16: break;
    default:
    throw new RuntimeException("传入参数有误!");
    }
      

  2.   

    不用switch 只想到要写16个ACTION
      

  3.   

    这个不是很好弄 啊?先把所有的数据放到一个List里面,然后根据id的值找到list相应的位置
    代码见下面:
    List list = 所有的数据 ;
    String tid = request.getParameter("id") ;
    int id$d = 0 ;
    boolean check = true ;
    try{
       id$d = Intager.paseInt(tid) ;
    }catch(NumberFormatException e){
       //some Exception hend here
       check = false ;
    }if(check){
       User user = list.get(id$d) ;
    }else{
       out.print("<script>history.back();</script>");
    }
      

  4.   


    case 16:
    request.setAttribute("menu", "123");
    request.setAttribute("message", "您确定要开通×××功能吗?功能费"
    + ××× + "元/月,开通请点击确认,放弃请点击取消。");
    request.setAttribute("yesurl", path
    + "/××.do?id=" + id.intValue());
    request.setAttribute("nourl", path
    + "/××.do");
    break;要传一次确认。。
    case 16: 

    request.setAttribute("menu", "123"); if ("0".equals(result)) {
    request.setAttribute("message",  "操作成功,已经××功能,系统将在24小时之内××。");
    } else {
    request.setAttribute("message", result);
    }

    break;确认后再给出结果
    目前想到的是XML或放到数据库里面 好像数据库好些
    然后存到MAP
     menu message对每个ID都是可变的反馈message估计没办法做成模版没法固定