Map<String, Object>返回类型
当一个方法想要返回不止一个参数时,可以定义Map类型做返回类型,具体代码例子如下:
public Map<String, Object> testMethod(List<Question> questions) { Map<String, Object> map = new HashMap<>(); List<Question> questions1 = new ArrayList<>(); questions1.addAll(questions); int reNum = 0; for (Question mu : questionService.list()) { for (Question m : questions) { if (m.getName().equals(mu.getName())) { questions1.remove(m); } } } reNum=questions.size()-questions1.size(); map.put("questionList", questions1); map.put("reNum", reNum); return map; }
最后要获取这些数据的时候这样子获取:
Map<String,Object> map = excelService.testMethod(questionList); int reNumber = (int) map.get("reNum"); List<Question> questions = (List<Question>) map.get("questionList");