0
我正在做一個關於Spring和YUI數據表的項目。在Spring MVC中顯示YUI數據表時出現數據錯誤
我正在使用控制器返回JSON字符串,並在視圖中將使用JSON字符串作爲數據源來生成數據表。但不知何故數據表顯示「數據錯誤」。
這裏是代碼爲我控制器:
@RequestMapping(值= 「/報告」) 公衆的ModelAndView getViolationReport(龍violation_num){
ComplLog origViolation = null;
//HashMap<Long, BRMap> logdetailsmap = new HashMap<Long, BRMap>();
Map<String,String> map = new HashMap<String, String>();
map.put("col1", "value1");
map.put("col2", "value2");
map.put("col3", "value3");
map.put("col4", "value4");
map.put("col5", "value5");
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
list.add(map);
ModelAndView mav = new ModelAndView();
mav.addObject("detailList", list);
mav.setViewName("GetViolationReport"); //return the model to the GetViolationReport.jsp
return mav;
}
這裏是我的index.jsp文件:
<% response.sendRedirect("/app/ViolationReportService.app"); %>
這是我的看法,GetViolationReport.jsp:
<body class="yui-skin-sam" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<div id="scroller" class="scrollPane">
<c:out value = "${detailList}" />
</div>
<div id="basic"></div>
</body>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.Basic = function() {
var myColumnDefs = [
{key:"col1", sortable:true, resizeable:true},
{key:"col2", sortable:true, resizeable:true},
{key:"col3", sortable:true, resizeable:true},
{key:"col4", sortable:true, resizeable:true},
{key:"col5", sortable:true, resizeable:true}
];
var myDataSource = new YAHOO.util.XHRDataSource("app/violationreport/report");
myDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
myDataSource.responseSchema = {
metaFields : {
totalRecords : "detailmap.totalRecordsFound",
recordsReturned : "detailmap.totalRecordsFound",
invocationStatus : "invocationStatus",
startIndex : 0,
executionStatusMessage : "executionStatusMessage"
},
resultsList : "detailList",
fields : [ "col1","col2","col3","col4","col5" ]
}
var myDataTable = new YAHOO.widget.DataTable("basic",
myColumnDefs, myDataSource, {initialLoad: true, caption:"DataTable Caption"});
return {
oDS: myDataSource,
oDT: myDataTable
};
}();
});
</script>
而且actoolkit-config.xml中是這樣的:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="favorParameter" value="true" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="html" value="text/html" />
<entry key="plain" value="text/plain" />
<entry key="octet" value="application/octet-stream" />
</map>
</property>
<property name="viewResolvers">
<list>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
<property name="defaultContentType" value="application/json" />
</bean>
有在控制檯沒有錯誤,但是當我去的是自己生成的數據表的URL,它顯示的數據表與我定義的列但內容顯示「數據錯誤」。
有人可以幫助我嗎?
現在我可以獲取要顯示的數據,但是我將請求映射更改爲@RequestMapping(value =「/ report/{violation_num}」),所以如果我想讓數據表顯示我從數據庫獲得的數據,我必須首先訪問http:// *****/app/violationreport/report/123124以獲取JSON數據,然後轉至*****/violationreportservice /調用數據表以使其顯示.. 。有沒有什麼辦法可以去http:// *****/app/violationreport/report/123124,然後直接在數據表中獲取數據? –
我不知道你在說什麼。這可以是YUI問題或Spring問題。到目前爲止,我們不知道。決定它的一種方法是讓你顯示瀏覽器實際獲得的內容。如果這是正確的,那麼這是一個YUI問題,如果它是錯誤的,那麼這是一個Spring問題。 – user32225
我終於搞定了,這實際上是因爲我在數據源中寫了一個錯誤的url。我將它改爲「http://....../**.json」,然後我得到要顯示的數據表。 –