第五章:配置使用FastJson返回Json视图

感谢作者:https://www.jianshu.com/p/14df78573cb2


一、添加FastJson依赖


二、创建FastJsonConfiguration配置信息类

    1.SpringBoot2需 实现 WebMvcConfigurer

    由于WebMvcConfigurerAdapter已废弃,配置类继承WebMvcConfigurerAdapter的方式改为实现WebMvcConfigurer接口,然后接口中的方法都是default的,不需要全部重写,此处只重写configureMessageConverters方法

    2.SpringBoot需 继承 WebMvcConfigurerAdapter


三、运行项目

访问地址: http://localhost:8080/user/list

接下来我们该如何去测试fastJson是否已经生效了呢?

先去除处理中文乱码

name的值从NULL变成了"",那么证明我们的fastJson消息的转换配置完美生效了, 只是处理乱码不完美.

猜你喜欢

转载自blog.csdn.net/q343509740/article/details/80822273