在线考试————随机出题

// 获取前台页面的值
	// 随机出现 题目

	@RequestMapping(value = "/queryQuestion")
	public String queryQuestion(TestQuestion ques, HttpServletRequest request) {
		// 获取 前台 输入个数数组 写死直接尽心个获取比较
		// 获取所有的题目主干
		// List<Map<String, Object>> radioCounts =
		// disposeService.queryQuestions();
		// 存放 option 表的内容

		List<Map<String, Object>> radioOptionCount = disposeService.queryOption();

		// 抽取单选
		List<Map<String, Object>> danXuan = disposeService.queryQuestionDanxuan();
		// 抽取多选
		List<Map<String, Object>> duoXuan = disposeService.queryDuoQuestions();
		// 抽取判断
		List<Map<String, Object>> panDuan = disposeService.queryPanQuestions();

		// 获取长度
		// int radionCount = radioCounts.size();
		// 获取单选长度
		int danXuans = danXuan.size();
		// 获取多选的长度
		int duoXuans = duoXuan.size();
		// 获取 判断
		int panDuans = panDuan.size();

		// 随机页面上单选的值
		// String radios = request.getParameter("radios");
		// int radioLen = Integer.parseInt(radios);
		// 获取单选的值
		// String radioGrade=request.getParameter("radioGrade");

		// 用空数组盛放单选
		int[] arr = new int[3];
		// 判断是否在里面
		String str = "";
		// 用空数组盛放多选
		int[] arr2 = new int[2];
		// 判断是否在里面
		String str2 = "";
		// 用空数组盛放判断
		int[] arr3 = new int[1];
		// 判断是否在里面
		String str3 = "";
		Random r1 = new Random();
		// 单选
		for (int i = 0; i < 3; i++) {
			int random = r1.nextInt(danXuans);// 如果1-6随机取3个数
			// 当值是11 或者 是1 时候进行区别
			while (str.lastIndexOf("," + random + ",") != -1) {
				random = r1.nextInt(danXuans);

			}
			// 存入 arr中
			arr[i] = random;
			str += "," + random + ",";

		}
		// 多选
		for (int i = 0; i < 2; i++) {
			int random = r1.nextInt(duoXuans);// 如果1-6随机取3个数
			// 当值是11 或者 是1 时候进行区别
			while (str2.lastIndexOf("," + random + ",") != -1) {
				random = r1.nextInt(duoXuans);
			}
			// 存入 arr中
			arr2[i] = random;
			str3 += "," + random + ",";

		}
		// 判断
		for (int i = 0; i < 1; i++) {
			int random = r1.nextInt(panDuans);// 如果1-6随机取3个数
			// 当值是11 或者 是1 时候进行区别
			while (str3.lastIndexOf("," + random + ",") != -1) {
				random = r1.nextInt(panDuans);
			}
			// 存入 arr中
			arr3[i] = random;
			str3 += "," + random + ",";

		}
		// 添加到radioList 集合中
		// List<Map<String, Object>> radioList = new ArrayList<Map<String,
		// Object>>();
		// 单选集合
		List<Map<String, Object>> danxuanQuestion = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < arr.length; i++) {
			danxuanQuestion.add(danXuan.get(arr[i]));
		}

		// 多选集合
		List<Map<String, Object>> duoxuanQuestion = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < arr2.length; i++) {
			duoxuanQuestion.add(duoXuan.get(arr2[i]));
		}

		// 判断集合
		List<Map<String, Object>> panduanQuestion = new ArrayList<Map<String, Object>>();

		for (int i = 0; i < arr3.length; i++) {
			panduanQuestion.add(panDuan.get(arr3[i]));
		}
		List<Map<String, Object>> radioList = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : danxuanQuestion) {
			radioList.add(map);

		}

		for (Map<String, Object> map2 : duoxuanQuestion) {
			radioList.add(map2);

		}
		for (Map<String, Object> map3 : panduanQuestion) {
			radioList.add(map3);

		}

		request.setAttribute("radioList", radioList);
		request.setAttribute("optionList", radioOptionCount);
		request.setAttribute("listLength", radioList.size());
		return "/sys/examQuestion";
	}

 个

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注