【ssm框架】添加json支持

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Hemk340200600/article/details/78145509

在ssm框架中添加json支持其实很简单。只需要几步即可完成。

第一步:在spring-mvc.xml中配置

<!-- 输出对象转JSON支持 -->
<bean id="jsonConverter"
     class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    <propertyname="supportedMediaTypes">
        <list>
           <value>application/json;charset=UTF-8</value>
        </list>
    </property>
</bean>


第二步:在controller方法头上面添加注解@ResponseBody

@RequestMapping(value = "/list.json",produces = "application/json;charset=utf-8")
@ResponseBody
public EUDataGridResult list(Model model, Integer page, Integer rows,Longtaskid) throws Exception{
    EUDataGridResult result = new EUDataGridResult();
    PageInfo<DefenseGroup> pageInfo =defenseGroupService.listAll(page,rows,taskid);
    result.setTotal(pageInfo.getTotal());
    result.setRows(pageInfo.getList());
    return result;
}

这样最终回传的数据就会变成json格式了

猜你喜欢

转载自blog.csdn.net/Hemk340200600/article/details/78145509
今日推荐