如何使用此json响应加载日历

时间:2018-02-12 08:01:50

标签: java json spring

我得到一个像这样的json响应如何将presentList数组映射到日历

{
    "error": false,
    "errorCode": null,
    "message": null,
    "response": {
        "classId": 1,
        "classSubjectMapId": null,
        "studentId": 66,
        "attendance": {
            "presentList": [
                "2017-01-03",
                "2017-01-01"
            ],
            "presentCount": 5,
            "absentList": []
        },
        "totalClassCount": 2
    }
}

这里我使用Fullcalender api来加载全尺寸日历家伙帮我解决这个问题.........................

$(document).ready(function() {
    $('#calendar').fullCalendar({

        header: {
            right: 'prev,next today'
        },

        defaultDate: '2017-01-01',
        editable: true,
        eventLimit: true,  // allow "more" link when too many events
        height: 572,

        events: 
            [ 
               {
                   start: "2017-01-03",
                   rendering: 'background',
                   color: '#ff0000'
               },  
               {
                   start: "2017-01-01",
                   rendering: 'background',
                   color: '#ff0000'
               } 
            ]     
        });
    }); 
}

我的控制器是这个我如何映射这个帮助我们在这里我得到现在阵列我如何通过事件。

@RequestMapping(value = "/ShowCalender", method = RequestMethod.GET)
public ModelAndView ShowCalender(HttpServletRequest request) {
    try {
        ModelAndView model = new ModelAndView("ShowCalender");

        String uri = "http://qnabubackend-env.2fuz4eh5jh.ap-south-1.elasticbeanstalk.com/attendance/api/student/attendances/v2/1/69"/*+ classId+"/"+ id*/;

        RestTemplate restTemplate = new RestTemplate();
        String Attendance = restTemplate.getForObject(uri, String.class);

        // build a JSON object

        List<AttendanceCalendarInfo> attendanceCalendarInfoArray = new ArrayList<AttendanceCalendarInfo>();
        ObjectMapper mapper = new ObjectMapper();
        JSONObject obj = new JSONObject(Attendance);

        JSONObject objects = obj.getJSONObject("response");

        AttendanceCalendarInfo attendanceCalendarInfo = mapper.readValue(objects.toString(),AttendanceCalendarInfo.class);
        attendanceCalendarInfoArray.add(attendanceCalendarInfo);

        JSONObject obj1 = objects.getJSONObject("attendance");
        System.out.println(obj1);
        //Object presentCount = obj1.get("presentCount");
        //System.out.println("presentCount>>>>>>>>>>>>>>>>" + presentCount);

        JSONArray presentList = obj1.getJSONArray("presentList");

        /* int i;

        for (i = 0; i < presentList.length(); i++) {

            System.out.println(presentList.get(i));
        }
*/              
             System.out.println("presentList>>>>>>>>>>>>>>>>>>>>>>>>>>>"+presentList);

        model.addObject("theAttendance", attendanceCalendarInfoArray);

        return model;
    } catch (Exception e) {
        return exceptionHandler(e);
    }
}

1 个答案:

答案 0 :(得分:0)

事件也可以作为json feed加载,如下所示。

$(document).ready(function() {
    $('#calendar').fullCalendar({

        header: {
            right: 'prev,next today'
        },

        defaultDate: '2017-01-01',
        editable: true,
        eventLimit: true,  // allow "more" link when too many events
        height: 572,

        eventSources: [ 
              {
                url: '/ShowCalender', 
                rendering: 'background',
                color: '#ff0000' 
             }


        });
    }); 
}

你有没有探索过它?链接here