我正在做一个关于 Spring 和 YUI 数据表的项目。
我正在使用控制器返回 JSON 字符串,并且在视图中将使用 JSON 字符串作为数据源来生成数据表。但不知何故,数据表显示“数据错误”。
这是我的控制器的代码:
@RequestMapping(value = "/report") public ModelAndView getViolationReport(Long 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 时,它显示了一个包含我定义的列的数据表,但内容显示“数据错误”。
有人可以帮我吗?