`
liukai
  • 浏览: 702782 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

丑陋的代码

    博客分类:
  • java
 
阅读更多
		/*
		 * 获得页面的Map集合,并迭代出来 获得答题ID和选中答题下标 根据选中答题的下标使得投票选项同样的下标+1
		 * 
		 */
		Map map = request.getParameterMap();
		for (Object obj : map.keySet()) {
			String[] va = (String[]) map.get(obj);
			// getParameterMap方法似乎会获得form里所有传递的值,想到的办法只有把其它传值参数的key过滤掉
			if (!"p_submit_type_id".equals(obj) && !"editId".equals(obj)) {
				Question question = manager.getQuestionOfBallot(obj.toString());// 根据问题ID获得对应的选项
				String[] temp = question.getBallot().split("\\|"); // 分割选项投票
				int ballot_temp;
				for (int i = 0; i < va.length; i++) {
					int option_id_int = Integer.parseInt(va[i]);// 投票选项的下标
					ballot_temp = Integer.parseInt(temp[option_id_int]) + 1; // 使选择的投票选项的下标选项+1
					temp[option_id_int] = String.valueOf(ballot_temp); // +1后装入临时变量中
				}
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < temp.length; i++) {
					sb.append(temp[i] + "|");
				}
				int r = manager.updateQuestionOfBallot(obj.toString(), sb
						.toString());
				PrintWriter out = response.getWriter();
				response.setCharacterEncoding("utf-8");
				if (r == 999) {
					out.write("0");
					out.flush();
					out.close();
				}
				out.write("1");
				out.flush();
				out.close();

			}
		}


没什么想说的 留下当个教训吧
目前的水平想不到更好的方法实现了
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics