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");

 

posted @ 2020-05-15 23:27  miracle2  阅读(6838)  评论(0编辑  收藏  举报