spring mvc 与fastjson集合

在使用spring mvc框架时候,有时候请求需要返回json格式.spring默认使用jackjson,但是我需要用fastjson,每次手动转换比较麻烦,需要spring自动为我转换,配置代码如下

Spring版本4.0.0

默认使用jackjson的配置
<annotation-driven>
</annotation-driven> 

使用fastjson的配置
    <annotation-driven>
      <message-converters register-defaults="true">
          <beans:bean id="fastJsonHttpMessageConverter" 
class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <beans:property name="supportedMediaTypes">
                    <beans:list>
                        <beans:value>application/json</beans:value>
                    </beans:list>
                </beans:property>
            </beans:bean>
        </message-converters>
    </annotation-driven>

spring mvc 与fastjson集合

时间: 2024-08-09 15:51:42

spring mvc 与fastjson集合的相关文章

spring mvc 如何传递集合参数(list,数组)

spring mvc 可以自动的帮你封装参数成为对象,不用自己手动的通过request一个一个的获取参数,但是这样自动的参数封装碰碰到了集合参数可能就需要点小技巧才可以了. 一.基础类型和引用类型有什么区别? 基础类型是直接保存在堆栈上面的,引用类型(对象)值保存在堆上面,地址保存在栈上面的,基础类型都有非null的默认值,比如int默认是0,boolean默认是false,引用类型除非是用new开辟出新的空间,否则只有地址信息没有值信息.int 和 integer的区别不仅是有没有默认值的问题

spring mvc接收List集合、JUI传JSP List

JUI页面是这样的 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <div class="tabsContent" style="height: 150px;">     <div>         <table class="list nowrap itemDetail" addButton="新建诊疗服务录

Spring MVC整合fastjson、EasyUI乱码问题

一.框架版本 Spring MVC:spring-webmvc-4.0.0.RELEASE fastjson:fastjson-1.2.45 EasyUI:1.5 二.乱码现象 Controller调用方法,输出到浏览器,出现乱码 1 @ResponseBody 2 @RequestMapping("/getManyEducation") 3 public String getManyCategory() { 4 List<Education> es = education

Spring MVC在接收复杂集合参数

Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是application/json,因此发送POST请求时需要设置请求报文头信息,否则Spring MVC在解析集合请求参数时不会自动的转换成JSON数据再解析成相应的集合.以下列举接收List<String>.List<User>.List<Map<String,Object>&g

记spring mvc传入List&lt;Object&gt;的一次尝试

首先,看一段异常: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized token 'entityList': was expecting ('true', 'false' or 'null') 标记的是实体中定义的属性值,实体如下: @Data public class ColumnsVO { List<GridColumnInfoEn

spring mvc 如何从前台表单传递集合参数并绑定集合对象

前端传递集合: <tr>    <td>    <select name="indtablelist[0].commodity_id">        <c:forEach items="${commoditys}" var="comm">        <option value="${comm.id}">${comm.commodity_no}||${comm.c

Spring Boot 实践折腾记(五):自定义配置,扩展Spring MVC配置并使用fastjson

每日金句 专注和简单一直是我的秘诀之一.简单可能比复杂更难做到:你必须努力理清思路,从而使其变得简单.但最终这是值得的,因为一旦你做到了,便可以创造奇迹.--源自乔布斯 题记 前两天有点忙,没有连续更新,今天接着聊.金句里老乔的话说得多好,但能真正做到的人又有多少?至少就我个人而言,我还远远没有做到这样,只是一个在朝着这个方向努力的人,力求简明易懂,用大白话让人快速的明白理解,简单的例子上手,让使用的人更多的去实战使用扩展,折腾记即是对自己学习使用很好的一次总结,对看的人也是一个参考的方法,希望

Spring mvc接受集合类型参数的方法

public String xxxxx(String xxxx, String xxxxx, @RequestParam("parameterList[]") List<String> parameterList) 方法比较简单,就是在参数名前边加上 @RequestParam("parameterList[]")注解,告诉Spring mvc这是一个集合类型的参数 原文地址:https://www.cnblogs.com/LionheartCGJ/p/

FreeMarker与Spring MVC 4集合的HelloWorld示例

0.整体的项目结构 1.引入POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">