저는 Spring을 배우는 수단으로 Java Servlet 기반 webapp를 변환 해 왔습니다. 큰 테이블의 데이터가 출력되는 JSP가 있습니다. 저는 Spring Controller 함수를 사용하여 HTML 테이블 행에 래핑 된 데이터의 큰 팻 문자열을 JSP로 반환합니다. 여기서 스크롤 div에 저장됩니다.Spring 3.1 및 JQuery EasyUI DataGrid : 예제 HashMaps 보내기, 예제?
대신 JQuery EasyUI DataGrid을 사용하고 싶습니다. 그러나 Ajax, JQuery 및 JSON도 처음이므로 머리말을 붙이는 방법에 관해서 조금 머리를 긁적입니다.
이
는 빈 테이블과 JQuery와 EasyUI 데이터 그리드와 열 머리글 설정 할 방법의 예입니다 :<table id="tt" title="Frozen Columns" class="easyui-datagrid" style="width:500px;height:250px"
url="data/datagrid_data.json"
singleSelect="true" iconCls="icon-save">
<thead frozen="true">
<tr>
<th field="itemid" width="80">Item ID</th>
<th field="productid" width="80">Product ID</th>
</tr>
</thead>
<thead>
<tr>
<th field="listprice" width="80" align="right">List Price</th>
<th field="unitcost" width="80" align="right">Unit Cost</th>
<th field="attr1" width="150">Attribute</th>
<th field="status" width="60" align="center">Stauts</th>
</tr>
</thead>
</table>
을하고 이것은 당신이 자바 스크립트 기능으로 테이블을 훅 방법은 다음과 같습니다
$('#tt').datagrid({
title:'Frozen Columns',
iconCls:'icon-save',
width:500,
height:250,
url:'data/datagrid_data.json',
frozenColumns:[[
{field:'itemid',title:'Item ID',width:80},
{field:'productid',title:'Product ID',width:80},
]],
columns:[[
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:100},
{field:'status',title:'Status',width:60}
]]
});
첫 번째 질문은 위의 예에서 "url"속성에 "/ getTabularData"와 같은 URL을 넣으면 스프링 3.1 컨트롤러의 함수에 매핑됩니다. 그렇다면 DataGrid가 해당 URL에 요청을 보내도록 트리거합니다 (문서는 조금 단순합니다). 내 이해하는
이
{"total":28,"rows":[
{"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":16.50,"attr1":"Large","itemid":"EST-1"},
{"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
{"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"},
{"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Rattleless","itemid":"EST-12"},
{"productid":"RP-LI-02","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Green Adult","itemid":"EST-13"},
{"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":58.50,"attr1":"Tailless","itemid":"EST-14"},
{"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"With tail","itemid":"EST-15"},
{"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Female","itemid":"EST-16"},
{"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Male","itemid":"EST-17"},
{"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":193.50,"attr1":"Adult Male","itemid":"EST-18"}
]}
처럼 감싸 데이터 행을 필요로 할 것 데이터 그리드는 JSON 포맷인가요?
단지 1 - 2 브리핑 JSON으로 다시 데이터를 보내는 스프링 3.1 컨트롤러 메소드의 예제를 찾을 수있었습니다. 기본적으로 유일한 차이점은 반환 유형이 @ResponseBody를 포함한다는 것입니다. 나는이 Spring Source Blog Entry을 찾았지만, 내가 이해하는 범위를 벗어난 인데, 단지입니다. Spring에서 JSON을 전송하는 방법에 대해 자세히 설명하는 다른 URL이 있습니까?
지금 내 응용 프로그램은 우리 데이터베이스에서 LinkedHashMaps 목록으로 데이터를 검색하고 있습니다.이 목록은 집계 함수에 포함되어 각 LinkedHashMap을 HTML TR로 래핑하고이를 모두 StringBuffer로 변환합니다.
JQuery EasyUI DataGrid를 사용하는 경우 LinkedHashMap obj 목록을 JSON으로 가져 와서 Spring에서 JSP 및 DataGrid로 반환하는 좋은 방법이 될 것입니다.
큰 "보여줘"질문은 싫지만 Google을 통해 작은 정보를 찾지 못했고 사용하고있는 모든 것을 처음 접했습니다. 어떤 도움 사전에 많은
덕분에
스티브
그 덕분에, 많이 감사합니다. 어떻게 당신이나 블로그 기사 작성자가 그 방식으로 데이터를 포위 (pojos)로 싸야한다는 것을 알았습니까? – Steve
JSON을 한 번 보아서 간단한 Java Collection으로 처리 할 수 없다고 말했습니다 ... 출력이 "행"부분 일 경우 대신 LinkedHashMaps List를 사용할 수 있습니다. – nickdos