我正在使用DataGrid来显示Spring MVC RestController中的数据。但是,当我在DataGrid URL参数中设置Controller路径时,则没有数据加载到DataGrid表中。我已经成功测试了来自服务器的JSON数据。所以我想知道我的代码怎么了?请帮助。
我尝试使用包含服务器响应数据的JSON文件。 DataGrid成功显示了我的所有记录。但是,当我使用控制器路径时,则不会显示任何数据。
其他控制器:
@CrossOrigin(origins = "*")
@RestController
public class CiudadanoController {
@Autowired
@Qualifier("persistenceFacade")
private PersistenciaFacade persistenceFacade;
@RequestMapping(value="/consultarCiudadanos.do")
@ResponseBody
public String consultarCiudadanos(){
List<CiudadanoDTO> result = new ArrayList<CiudadanoDTO>();
result.addAll(persistenceFacade.consultarCiudadanos());
Gson parser = new GsonBuilder().create();
DataGridResultDTO rows = new DataGridResultDTO();
rows.setTotal(result.size());
rows.setRows(result);
return parser.toJson(rows);
}
public PersistenciaFacade getPersistenceFacade() {
return persistenceFacade;
}
public void setPersistenceFacade(PersistenciaFacade persistenceFacade) {
this.persistenceFacade = persistenceFacade;
}
}
JSP页面:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/gray/easyui.css">
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/mobile.css">
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/icon.css">
<script type="text/javascript"
src="<%=request.getContextPath()%>/script/jquery.min.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/script/main.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/script/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/script/loadingoverlay.min.js"></script>
<title>Login</title>
</head>
<body>
<div class="easyui-panel">
<header>
<div class="m-toolbar">
<span class="m-title">Ciudadanos Registrados</span>
</div>
</header>
<div data-options="region:'west',split:true" style="width: 100%;">
<table id="ciudadanosTable" title="Ciudadanos" class="easyui-datagrid"
url="<%=request.getContextPath()%>/consultarCiudadanos.do"
scrollbarSize="1" pagination="true" method="get" autoLoad="true"
fitColumns="true" fit="true" singleSelect="true" >
<thead>
<tr>
<th data-options="field:'cedula',width:80">CC</th>
<th data-options="field:'nombre',width:100">Nombre</th>
<th data-options="field:'direccion',width:80,align:'right'">Direccion</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
我希望DataGrid包含RestController数据。我将不胜感激。
谢谢。