很多switch要如果改?求助!!! 用的是struts2 框架JSP传参数进来,例如 ×××.jsp?id=1根据id 进行业务方法调用就出现了很多switch 要如何改?页面的展示是查询数据库出来的LIST 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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("传入参数有误!"); } 不用switch 只想到要写16个ACTION 这个不是很好弄 啊?先把所有的数据放到一个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>");} 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估计没办法做成模版没法固定 Struts2,Hibernate,按照时间段查询 使用jsp调用tag文件时浏览器显示中文乱码怎么办? 太神奇了,太神奇了 使用struts-menu的2个问题,表可以更改吗?中文如何被显示呢? STRUTS问题 JDBC连接MS SQL出现异常 请教关于sql库连接的问题,(在线等待) JSP环境配置,不管对错,回答都有分,不够再加 刚申请了jsp空间,如何使用我的.class文件呢? axis2客户端调用问题 重定向和转发的区别都有哪些呢? 一个很烦人的问题
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("传入参数有误!");
}
代码见下面:
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>");
}
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估计没办法做成模版没法固定