让我回答我不使用Json我不知道如何使用我想要的 在日历中显示我的事件请帮助我#34; My db values is need to display as per date and with total count in particular date &#34 ;, 这是我的jsp代码
<div class="col-md-12">
<div class="card-box">
<div id="calendar"></div>
</div>
</div> <!-- end col -->
</div> <!-- end row -->
这是我在jsp页面中使用的完整日历脚本:
<script type="text/javascript">
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
url: '/leavecalender'; /* might be this is wrong ? */
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
events:[data]
});
});
</script>
这是我的控制器:
@RequestMapping(value = "/leavecalender")
public ModelAndView leave(ModelMap model)
{
TeleCallRecordIdTO telecall = new TeleCallRecordIdTO();
List<TeleCallRecordIdTO> allcall = hrService.getallcalls();
model.addAttribute("allcall", allcall);
return new ModelAndView("HR/hr/leavesCalender","leavecalender",telecall);
}
这是我的服务:
public List<TeleCallRecordIdTO> getallcalls();
这是我的serviceImplementation:
@Override
public List<TeleCallRecordIdTO> getallcalls() {
return hrDao.getallcalls();
}
这是我的Dao:
public List<TeleCallRecordIdTO> getallcalls();
这是myDaoImplementation:
@Override
public List<TeleCallRecordIdTO> getallcalls() {
List<TeleCallRecordIdTO> list = new ArrayList<>();
try {
String s = "SELECT DATE(call_date) AS 'Date', COUNT(1) AS 'TotalCalls'
FROM tele_call_record GROUP BY DATE(call_date)";
Connection connection=sessionFactory.getCurrentSession().connection();
PreparedStatement preparedStatement;
preparedStatement=connection.prepareStatement(s);
ResultSet rs= preparedStatement.executeQuery();
while(rs.next())
{
TeleCallRecordIdTO tel=new TeleCallRecordIdTO();
tel.setCallDate(rs.getString("Date"));
/*tel.setExtensionNo(rs.getString("extension_no"));
tel.setPhoneNo(rs.getString("phone_no"));*/
tel.setSrNo(rs.getInt("TotalCalls"));
list.add(tel);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
答案 0 :(得分:1)
如果我理解你的问题,你需要尝试这个
替换
events:[data]
events: function(start, end, timezone, callback) {
$.ajax({
url: '${pageContext.request.contextPath}/leavecalender',
//data: {
// data if you are passing
//},
success: function(data) {
var events = [];
$.each(data, function(index) {
events.push({
title: data[index].srNo,
start: data[index].callDate,
//end: data.end
});
});
callback(events);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log( textStatus +" - "+ errorThrown );
}
});
}
还要更改您的控制器方法:
@RequestMapping(value = "/leavecalender", method=RequestMethod.GET)
@ResponseBody
public List<TeleCallRecordIdTO> leave() {
return hrService.getallcalls();;
}