SpringMVC 集成fastjson
为什么80%的码农都做不了架构师?>>>
1、首先引入maven依赖包:
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.3</version>
</dependency>
2、由于在spring 3.1之后<mvc:annotation-driven />注册的类发生了变化,新版配置如下:
<!-- 配置自定义驱动 --><mvc:annotation-driven><mvc:message-converters><ref bean="fastJsonHttpMessageConverter"/> </mvc:message-converters></mvc:annotation-driven><!-- 配置Fastjson支持,返回json格式数据 --><bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value><value>application/json</value></list></property><property name="features"><list><value>WriteMapNullValue</value><value>QuoteFieldNames</value></list></property></bean>
3、数据返回,配置fastjson后,在ajax请求直接返回实体,fastjson会自动转换成json,如:
/*** @Title: table * @Description: TODO(返回表格数据) * @param 设定文件 * @return String 返回类型 * @throws*/@RequestMapping(value = "/table", method = RequestMethod.GET)@ResponseBodypublic PageInfo<BeatlesRegime> table(BeatlesRegime beatlesRegime) {return regimeService.table(beatlesRegime);}
4、返回数据格式附上:
{"endRow": 10,"firstPage": 1,"hasNextPage": true,"hasPreviousPage": false,"isFirstPage": true,"isLastPage": false,"lastPage": 2,"list": [{"content": "是谁,在四季中念起?","count": null,"createTime": 1502942251000,"filter": null,"id": "04595d0e409041a192f4e6513e04b993","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942251000},{"content": "那些发黄的信件,写满了青春时的不经意。而今,越来越安于世故的我们,总是小心翼翼的藏起自己。","count": null,"createTime": 1502942215000,"filter": null,"id": "10ae0e01a44c4e6582ca59f6f3558c8e","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942215000},{"content": "当时,我们不管不顾的挥霍着,时光和热爱。","count": null,"createTime": 1502942270000,"filter": null,"id": "227877dc6dbe4bcbbc92f61d0d750847","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942270000},{"content": "fawefwefaew","count": null,"createTime": 1502880400000,"filter": null,"id": "2b49c0ca3e4e4cab90fac2ced1ab569a","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502880400000},{"content": "“我活着,每一天感受着所有的细节和琐碎,并且尝试将它们位于欣赏的位置。”","count": null,"createTime": 1502942288000,"filter": null,"id": "4e1e60d170ab4942b72629b8f6c8f698","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942288000},{"content": "“谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳。被酒莫惊春睡重,赌书消得泼茶香,当时只道是寻常。”","count": null,"createTime": 1502942229000,"filter": null,"id": "5fe9e2200e43462bb01744e270d0d50b","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942229000},{"content": "我们一定是孤独的太久,甚至忘记了季节的呼唤。那一日,路过云端雾海,看远山隐约,山之巅处,我们明白了自己的微小。博大的秋色,颔首着一段段回旋的旋律,一遍一遍不厌其烦的弹奏着岁月的篇章。一丝一缕,一点一滴。","count": null,"createTime": 1502942187000,"filter": null,"id": "81d0580464db4eb38e79f241261d4a64","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942187000},{"content": "等到秋来,已是过往。","count": null,"createTime": 1502942276000,"filter": null,"id": "8d203a035f4e465c99b572a4faefda7c","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942276000},{"content": "秋天不迟到,立秋之后气温在早晚已经有了微凉,虽然中午还是热浪翻涌,可是一早一晚的温度,已经是相宜。","count": null,"createTime": 1502942159000,"filter": null,"id": "8d2049351764426c97fa37f7f8a598a6","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1502942159000},{"content": "The cell 的事件监听,当你使用formatter function的时候,有三个参数: event: the jQuery event. value: 该cell的值 row: 该行的数据 index: 该行的序号The cell 的事件监听,当你使用formatter function的时候,有三个参数: event: the jQuery event. value: 该cell的值 r","count": null,"createTime": 1503131096000,"filter": null,"id": "964cf1b549794471885a10a926a0b43e","limit": null,"offset": null,"operateDesc": null,"order": null,"sort": null,"updateTime": 1503131096000}],"navigateFirstPage": 1,"navigateLastPage": 2,"navigatePages": 8,"navigatepageNums": [1,2],"nextPage": 2,"pageNum": 1,"pageSize": 10,"pages": 2,"prePage": 0,"size": 10,"startRow": 1,"total": 19
}
转载于:https://my.oschina.net/qjedu/blog/1518188
SpringMVC 集成fastjson相关推荐
- SpringMvc 集成 shiro 实现权限角色管理-maven
2019独角兽企业重金招聘Python工程师标准>>> SpringMvc 集成 shiro 实现权限角色管理 1.项目清单展示 2.项目源码解析 1)spring-context ...
- springMVC集成缓存框架Ehcache
概述 Ehcache算是当前比较流行的缓存框架,使用缓存可以极大的缓解服务器和数据库的压力,提高访问效率,提高服务器的并发能力.接下来我们看怎么把缓存在spring mvc种使用起来. 详细 代码下载 ...
- springmvc集成cas,并解决前后端分离情况
2019独角兽企业重金招聘Python工程师标准>>> 1.最近项目需要集成已经存在的cas系统. 但是目前已集成的系统都是jsp.而我们项目是前后端分离开发(伪),没有分开部署. ...
- SpringMVC集成Quartz2.3.2
SpringMVC集成Quartz2.3.2 集成Quartz持久化 下载jar导入jar包 配置properties 配置xml数据源 导入数据表 xml配置中用到的工厂类 自定义Job Contr ...
- SpringMvc集成Springfox使用Swagger写文档和测试
SpringMvc集成Springfox使用Swagger写文档和测试 前言 swagger简介 swagger确实是个好东西,可以跟据业务代码自动生成相关的api接口文档,尤其用于restful风格 ...
- SpringMVC集成Redis集群
SpringMVC集成Redis集群的应用,使用了 log4j,@value,@Configuration,@Bean,jackson工具类 SpringMVC集成Redis集群 github res ...
- SpringMVC集成Hibernate Validator进行注解式的参数校验——让代码更少、更加专注于业务逻辑
SpringMVC集成Hibernate Validator进行注解式的参数校验 --让代码更少.更加专注于业务逻辑 1 问题背景: 参数验证是一个常见的问题,例如验证用户输入的密码是否为空.邮箱是否 ...
- SpringMVC(十三):SpringMVC 与fastjson集成
1)fastjson jar包下载地址:https://sourceforge.net/projects/fastjson/ 下载完成后需要把jar包拷贝到WEB-INF/lib文件夹中. 2)使用p ...
- SpringMVC 集成 JWT验证方式
JWT官网: https://jwt.io/ 这里以java的ssm框架为例,集成jwt. 1.pom.xml 导入jwt的包 <!-- jwt --> <dependency> ...
最新文章
- php判断数组是否存在字符串中,php判断数组元素中是否存在某个字符串的方法
- 算法导论之单源最短路径
- The Hystrix timeout of XXms for the command XX-XX is set lower than the combination of the
- VC++ 19 (VS2015) 编译器系统环境变量配置
- [Swift] 使用Playground
- Android中扫描wifi热点
- 读《构建之法》13--17章有感
- 搜狗深入布局人工智能 Q2营收利润创新高
- linux 深入检测io详情的工具iopp
- 使用CollectionViewSource,通过Xaml绑定自动排序
- 日常计算机使用的需求和解决方案(一)
- 超声前置放大器原理是什么意思,前置放大器和功放区别
- 极光推送官网android,极光推送(一)——配置
- 微信能转发邮件吗?邮件怎么用微信发送?微信邮件怎么发?
- 怎么打开和修改dll文件的?如何调用和编辑?
- Windows 7 查看默认的本地 DNS 服务器地址
- 仰望星空,脚踏实地 2016
- C. Petya and Exam
- java 对大数据的处理
- 我是怎样使用BoundsChecker的