cyper的java代碼(spring mvc controller): javascript
@RequestMapping(value = "calendarEvents") @ResponseBody public String calendarEvents(){ List<LecturerAgendaVo> agendas = lecturerAgendaService.findAllMatchedAgenda(); StringBuilder sb = new StringBuilder(); sb.append("["); for(LecturerAgendaVo agenda: agendas){ sb.append("{\"id\":" + agenda.getId()); sb.append(",\"title\":\"\\n" + agenda.getLecterName()+"\\n"); sb.append(agenda.getSchoolName()+"\\n"); sb.append(agenda.getStartTime() + "-"+ agenda.getEndTime() + "\\n"); sb.append("\""); sb.append(",\"start\":\"" + agenda.getLectDate() + " " + agenda.getStartTime() + ":00\""); sb.append(",\"end\":\"" + agenda.getLectDate() + " " + agenda.getEndTime() + ":00\""); sb.append("},"); } sb.setLength(sb.length()-1); sb.append("]"); return sb.toString(); }
cyper的javascript: java
$(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' }, editable: false, events: '${ctx}/mgr/lect/apply/calendarEvents.json' }); });
如下為轉載部分:
fullcalendar 的幫助文檔 可見地址:http://arshaw.com/fullcalendar/docs/ ajax
jQuery日曆FullCalendar插件是一個很是不錯的日曆工具,可用於製做日程表或計劃安排 spring
<pre class="javascript" name="code"> $('#calendar').fullCalendar({ events: { url: '<%=request.getContextPath()%>/displayAction.do?method=testJson' //你的controller的地址 type: 'POST', error: function() { alert('there was an error while fetching events!'); }, color:'yellow',// 背景色 textColor:'black'// 文字顏色 } });</pre> <pre></pre>
java代碼 json
public ModelAndView testJson(HttpServletRequest request, HttpServletResponse response) { String strvalue = "[{\"id\":111,\"title\":\"Event1\",\"start\":\"2012-03-10\",\"url\":\"http:\\/\\/yahoo.com\\/\"},{\"id\":222,\"title\":\"Event2\",\"start\":\"2012-03-20\",\"end\":\"2012-03-22\",\"url\":\"http:\\/\\/yahoo.com\\/\"}]"; response.setCharacterEncoding("UTF-8"); System.out.println("strvalue="+strvalue); try { response.getWriter().print(strvalue); } catch (IOException e) { e.printStackTrace(); } return null; }3 events (as a function)
$('#calendar').fullCalendar({ events:function(start, end, timezone, callback) { $.ajax({ url:"<%=request.getContextPath()%>/displayAction.do?method=getTitle", cache:false, success:function(doc) { eval("var j=" + doc); var events = []; var info = j.eventinfo; for (var i = 0; i < info.length; i++) { var ev = info[i]; var title = ev.title; var evtstart = new Date(Date.parse(ev.start)); var evtend = new Date(Date.parse(ev.end)); events.push({ title:title, start:evtstart, end:evtend, id:1 }); } callback(events); }, error:function() { alert('sdf') } }) } })
java代碼 mvc
public ModelAndView getTitle(HttpServletRequest request, HttpServletResponse response) { String strvalue = "{ 'eventinfo':[{day: '3/3/2012',eventtitle:'test1'},{day: '3/8/2012',eventtitle:'test2'} ]} "; response.setCharacterEncoding("UTF-8"); System.out.println("strvalue="+strvalue); try { response.getWriter().print(strvalue); } catch (IOException e) { e.printStackTrace(); } return null; }