Springを学習する手段として、JavaサーブレットベースのWebアプリを変換してきました。大きなデータテーブルが印刷されているJSPがあります。Spring Controller関数を使用して、HTMLテーブル行にラップされたデータの大きな太い文字列をJSPに返し、そこでスクロールdivに格納します。
代わりにJQueryEasyUIDataGridを使用したいのですが、Ajax、JQuery、JSONも初めてなので、全体をどのように配置するかについて少し頭を悩ませています。
これは、JQueryEasyUIDataGridを使用して空のテーブルと列ヘッダーを設定する方法の例です。
<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>
これは、テーブルをjavascript機能にフックする方法です。
$('#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を配置し、それをSpring3.1コントローラーの関数にマップするかどうかです。もしそうなら、何がDataGridをトリガーしてそのURLにリクエストを送信しますか(ドキュメントは少しミニマリストです)。
私の理解では、DataGridはこのようにラップされたデータ行を必要とします
{"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のフォーマットですか?
データをJSONとして送り返すSpring3.1Controllerメソッドの簡単な例を1〜2個しか見つけることができませんでした。基本的に異なるのは、returnタイプに@ResponseBodyが含まれることだけです。私はこのSpringSourceBlog Entryを見つけましたが、私と同じくらい新しいので、私の理解の範囲を超えています。SpringからJSONを送信する方法の詳細を説明する他のURLはありますか?
現在、私のアプリは、データベースからLinkedHashMapsのリストとしてデータを取得しています。このデータは、自家製の関数にドロップされ、各LinkedHashMapをHTML TRにラップして、すべてをStringBufferにまとめます。
JQuery EasyUI DataGridを使用する場合、LinkedHashMapオブジェクトのリストを取得してJSONに取得し、SpringからjspおよびDataGridに返すための適切なアプローチは何でしょうか。
このような大きな「方法を教えて」という質問をするのは嫌いですが、Googleでほんの少しの情報しか見つけることができず、使用しているすべてのものに慣れていません。
助けてくれてありがとう
スティーブ