我正在尝试使用 Kendo UI Grid 从数据库中填充数据。我正在创建的应用程序使用 Spring 3.2、Hibernate4 和 Jackson Fasterxml。我知道我的控制器正在返回 JSON。我知道这一点,因为当我点击为控制器调用的 URL 时,我得到以下 JSON 响应:
[{"applicationId":11,"applicationName":"LOS","url":"test.com","serverId":1,"serverName":"vmlosweb01","serverIp":"10.49.10.89","createdDate":1373644385213,"modifiedDate":null,"genericUserName":"lsdefault","genericPassword":"password1","orgId":null,"environmentId":1,"environmentName":"SANDBOX","createdDate":1373904291147,"modifiedDate":null,"databaseInfoId":1,"databaseName":"SANDBOX Database","ipAddress":"10.49.10.145","environmentId":1,"environmentName":"SANDBOX","createdDate":1373904291147,"modifiedDate":null,"createdDate":1373904415710,"modifiedDate":null,"createdDate":1374169441500,"modifiedDate":null}]
这是我的代码:
应用信息.js
$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
read: "/appinfo/findApplications",
dataType: "jsonp"
}
},
pageSize: 10
});
dataSource.fetch(function(){
var data = this.data();
console.log(data.length);
});
$("#applicationsGrid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 600,
scrollable: true,
sortable: true,
filterable: true,
columns: [
{field: "applicationName", title: "Application Name"},
{field: "url", title: "URL"},
{field: "serverId", title: "Server"},
{field: "environmentId", title: "Environment"},
{field: "databaseInfoId", title: "Database"},
{field: "genericUserName", title: "Default Username"},
{field: "genericPassword", title: "Default Password"}
]
});
});
应用信息控制器.java
package com.lps.appinfo.controller;
import com.lps.appinfo.model.*;
import com.lps.appinfo.service.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.lps.appinfo.service.DatabaseInfoService;
import com.lps.appinfo.service.EnvironmentService;
import com.lps.appinfo.service.ServerService;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Controller
public class ApplicationInformationController {
private static final Logger logger = LoggerFactory.getLogger(ApplicationInformationController.class);
@Autowired
private ApplicationService applicationService;
@Autowired
private EnvironmentService environmentService;
@Autowired
private ServerService serverService;
@Autowired
private DatabaseInfoService databaseInfoService;
@RequestMapping(value = "/findApplications", method = RequestMethod.GET, headers = "Accept=application/json")
public
@ResponseBody()
List<Application> findApplications() {
/* MappingJackson2HttpMessageConverter json = new MappingJackson2HttpMessageConverter();
MediaType jsonMimeType = MediaType.APPLICATION_JSON;*/
applicationService = new ApplicationService();
List<Application> applications = applicationService.getAll();
// json.write(new Object(), jsonMimeType, new ServletServerHttpResponse());
return applications;
}
}
当我通过 Chrome 调试器调试 javascript 时,dataSource 变量返回的数组大小为 0。所以我不确定发生了什么(或没有发生)。