easyui ajax请求获取SpringMVC @ResponseBody返回Json数据

前端之家收集整理的这篇文章主要介绍了easyui ajax请求获取SpringMVC @ResponseBody返回Json数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
controller层代码 @RequestMapping(value = "/list.htm") @ResponseBody private Object geUserList() {  ParamCondition paramCondition = getParamCondition();  PageModel pageModel = getPageModel();  userService.list(pageModel,paramCondition);    return setPageData(1,pageModel.getRows()); } protected Map<String,Object> setPageData(long total,Object rows) {  HashMap<String,Object> result = new HashMap<String,Object>();  result.put("total",total);  result.put("rows",rows);    return result; } easyui 前台请求,下面为datagrid url请求: $('#dg').datagrid({    url:$WEB_ROOT_PATH + '/user/list.htm',toolbar: '#tb',fit: true,pagination: true,rownumbers: true,singleSelect: true,columns:[[    {field:'ck',checkBox: true },{field:'username',title:'用户名',width:100},{field:'password',title:'密码',width:100}    ]],}); SpringMVC需要添加该配置:
<!-- 完成请求和注解POJO的映射 -->
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonConverter"/>
        </list>
    </property>
</bean>
需要jackson-core-asl-1.9.13.jar 、jackson-mapper-asl-1.9.13这两个jar包。

参考以下链接:
http://www.zuidaima.com/question/2205744784018432.htm
http://www.thinksaas.cn/group/topic/335349/

猜你在找的SpringMVC相关文章