0
我正在開發基於Web的項目與Spring MVC,休眠& jQuery與碼頭服務器.. 我想顯示有關JSON響應的數據。 這裏是控制器類的json方法。(我需要表現出港口在我的網格細節)在jqGrid中顯示Json數組數據
@Entity
@Table(name = 「港灣」) 公共類港{
@Id
@Column(name="HARBOUR_ID")
@GeneratedValue
private Integer harbourId;
@Column(name="HARBOURCODE")
private String harbourCode;
@Column(name="HARBOURNAME")
private String harbourName;
@Column(name="STREETNO")
private String streetNo;
@Column(name="STREETONE")
private String streetOne;
@Column(name="STREETTWO")
private String streetTwo;
@Column(name="CITYNAME")
private String cityName;
@Column(name="PROVINCE")
private String province;
@Column(name="ALL_ID")
private String allocationId; & Getter & Setters
&這是我的控制器類方法,用於生成json數組作爲響應
@RequestMapping("/selectHarbour")
public ModelAndView selectHarbour(Map<String, Object> map,HttpServletRequest request,
HttpServletResponse response) {
try {
List <Harbour> list= harbourService.listHarbour();
JSONArray jsonArray=new JSONArray();
for(Harbour harbour:list){
JSONArray array=new JSONArray();
array.put(harbour.getHarbourId());
array.put(harbour.getHarbourCode());
array.put(harbour.getHarbourName());
array.put(harbour.getCityName());
array.put(harbour.getProvince());
jsonArray.put(array);
}
response.getWriter().write(jsonArray.toString());
return null;
}catch(Exception exception){
System.out.println("error is "+exception);
}
return null;
}
最後,這是我的jquery生成jqGrid。
<td colspan="2">
<!-- Insert Data Tables -->
<table id="list5"></table>
<div id="pager5"></div>
<br />
<a href="#" id="a1">Get data from selected row</a>
<br />
</td>
<script type="text/javascript">
jQuery("#list5").jqGrid({
url:'selectHarbour.html',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager5',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"Simple data manipulation",
editurl:""
}).navGrid("#pager5",
{edit:false,add:false,del:false});
jQuery("#a1").click(function(){
var id = jQuery("#list5").jqGrid('getGridParam','selrow');
if (id) {
var ret = jQuery("#list5").jqGrid('getRowData',id);
alert("id="+ret.id+" invdate="+ret.invdate+"...");
} else { alert("Please select row");}
});
</script>
&
螢火蟲這樣表示我的反應..
[5, 「CLM」, 「科倫坡」, 「科倫坡」, 「西方」],[ 6,「HMB」,「Hambanthota」,「Colombo 07」,「Southern」]]
然後朋友,我的錯誤在哪裏? ? ?數據未顯示在我的網格中
是否需要jsonReader選項? – priyalhdp