当前位置: 首页 > news >正文

莆田城市投资建设集团网站自己做的网站怎么管理用户

莆田城市投资建设集团网站,自己做的网站怎么管理用户,wordpress更改地址,淘宝网上购物平台文章目录 错误描述问题分析打印目前所有的消息处理器寻找适配版本消息解释器加载顺序 错误原因正确写法使用最新版本fastjson(2024-1-22)配置fastjson2消息转换器(保留系统原消息转换器)替换消息转换器配置fastjson2 错误描述 采用Bean的方式配置FastJsonHttpMessageConverter… 文章目录 错误描述问题分析打印目前所有的消息处理器寻找适配版本消息解释器加载顺序 错误原因正确写法使用最新版本fastjson(2024-1-22)配置fastjson2消息转换器(保留系统原消息转换器)替换消息转换器配置fastjson2 错误描述 采用Bean的方式配置FastJsonHttpMessageConverter消息解释器实测在【SpringBoot2.6.13】未生效 但是在【SpringBoot2.1.4.RELEASE】版本中正常 2.1.4.RELEASE中引入如下 dependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion1.2.56/version/dependency配置如下 import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;Beanpublic HttpMessageConverters fastJsonHttpMessageConverters() {FastJsonHttpMessageConverter fastConverter new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig new FastJsonConfig();fastJsonConfig.setDateFormat(yyyy-MM-dd HH:mm:ss);fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.QuoteFieldNames,SerializerFeature.WriteEnumUsingName,SerializerFeature.DisableCircularReferenceDetect);ListMediaType fastMediaTypes new ArrayList();fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);fastConverter.setSupportedMediaTypes(fastMediaTypes);fastConverter.setFastJsonConfig(fastJsonConfig);return new HttpMessageConverters(fastConverter);}问题分析 打印目前所有的消息处理器 通过打印消息处理器发现配置并未成功 public class MvcConfig implements WebMvcConfigurer {Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {for (HttpMessageConverter? messageConverter : converters) {System.out.println(messageConverter);}} }得到如下输出日志 org.springframework.http.converter.ByteArrayHttpMessageConverter1ddf42dd org.springframework.http.converter.StringHttpMessageConverter5c1c9881 org.springframework.http.converter.ResourceHttpMessageConverter1c18ee69 org.springframework.http.converter.ResourceRegionHttpMessageConverter2f99d8c org.springframework.http.converter.xml.SourceHttpMessageConverter65d7eea4 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter5d37aa0f org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter6076c66 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter485c84d7寻找适配版本 官网可知fastjson早已停止更新新版本需使用fastjson2 在 Spring 中集成 Fastjson2 | fastjson2 (alibaba.github.io) 引入如下 dependencygroupIdcom.alibaba.fastjson2/groupIdartifactIdfastjson2-extension-spring5/artifactIdversion2.0.43/version /dependency官网得到如下配置 Configuration EnableWebMvc public class WebMvcConfigurer extends WebMvcConfigurerAdapter {Overridepublic void configureMessageConverters(ListHttpMessageConverter? converters) {FastJsonHttpMessageConverter converter new FastJsonHttpMessageConverter();//自定义配置...FastJsonConfig config new FastJsonConfig();config.setDateFormat(yyyy-MM-dd HH:mm:ss);config.setReaderFeatures(JSONReader.Feature.FieldBased, JSONReader.Feature.SupportArrayToBean);config.setWriterFeatures(JSONWriter.Feature.WriteMapNullValue, JSONWriter.Feature.PrettyFormat);converter.setFastJsonConfig(config);converter.setDefaultCharset(StandardCharsets.UTF_8);converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));converters.add(0, converter);} }消息解释器加载顺序 需要将FastJsonHttpMessageConverter配置为第一位消息处理器才能得到输出 其测试过程如下 converters.add(converter);此时得到输出为 org.springframework.http.converter.ByteArrayHttpMessageConverter1ddf42dd org.springframework.http.converter.StringHttpMessageConverter5c1c9881 org.springframework.http.converter.ResourceHttpMessageConverter1c18ee69 org.springframework.http.converter.ResourceRegionHttpMessageConverter2f99d8c org.springframework.http.converter.xml.SourceHttpMessageConverter65d7eea4 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter5d37aa0f org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter6076c66 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter485c84d7 com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter1224e1b6实测未生效 {code: 200,msg: 请求成功,data: {loginName: null,userName: 柒杉,userCode: null,loginDate: 1705547281595} }修改为 converters.add(0, converter);得到输出 com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter2a667f44 org.springframework.http.converter.ByteArrayHttpMessageConverter53ba7997 org.springframework.http.converter.StringHttpMessageConverter3f6f9cef org.springframework.http.converter.ResourceHttpMessageConverter61dd1c3d org.springframework.http.converter.ResourceRegionHttpMessageConverter7858d31d org.springframework.http.converter.xml.SourceHttpMessageConverter782e6b40 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter3b65084e org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter32d0d7eb org.springframework.http.converter.json.MappingJackson2HttpMessageConvertercae2a97错误原因 在高版本中需要采用最新的fastjson2配置正确写法 使用最新版本fastjson(2024-1-22) dependencygroupIdcom.alibaba.fastjson2/groupIdartifactIdfastjson2-extension-spring5/artifactIdversion2.0.43/version /dependency配置fastjson2消息转换器(保留系统原消息转换器) Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {// 创建 FastJson 的消息转换器实例FastJsonHttpMessageConverter converter new FastJsonHttpMessageConverter();// 创建 FastJson 的配置实例FastJsonConfig config new FastJsonConfig();// 设置时间类型日期格式config.setDateFormat(yyyy-MM-dd HH:mm:ss);config.setReaderFeatures(// 基于字段序列化如果不配置会默认基于public的field和getter方法序列化。// 配置后会基于非static的field包括private做序列化。JSONReader.Feature.FieldBased,// 支持数据映射的方式JSONReader.Feature.SupportArrayToBean);config.setWriterFeatures(// 显示null与空字符串// JSONWriter.Feature.WriteMapNullValue,// 格式化输出JSONWriter.Feature.PrettyFormat,// 将Long序列化为StringJSONWriter.Feature.WriteLongAsString);// 将序列化配置设置到 FastJson 配置中converter.setFastJsonConfig(config);converter.setDefaultCharset(StandardCharsets.UTF_8);// 创建一个媒体类型表示支持 JSON 格式并使用 UTF-8 编码ListMediaType fastMediaTypes new ArrayList();MediaType utf8MediaType new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8);fastMediaTypes.add(utf8MediaType);converter.setSupportedMediaTypes(fastMediaTypes);// 将 FastJson 消息转换器添加到 Spring Boot 的消息转换器列表中位置是第一个这样确保它优先于其他消息转换器converters.add(0, converter);} 替换消息转换器配置fastjson2 Overridepublic void configureMessageConverters(ListHttpMessageConverter? converters) {// 创建 FastJson 的消息转换器实例FastJsonHttpMessageConverter converter new FastJsonHttpMessageConverter();// 创建 FastJson 的配置实例FastJsonConfig config new FastJsonConfig();// 设置时间类型日期格式config.setDateFormat(yyyy-MM-dd HH:mm:ss);config.setReaderFeatures(// 基于字段序列化如果不配置会默认基于public的field和getter方法序列化。// 配置后会基于非static的field包括private做序列化。JSONReader.Feature.FieldBased,// 支持数据映射的方式JSONReader.Feature.SupportArrayToBean);config.setWriterFeatures(// 显示null与空字符串// JSONWriter.Feature.WriteMapNullValue,// 格式化输出JSONWriter.Feature.PrettyFormat,// 将Long序列化为StringJSONWriter.Feature.WriteLongAsString);// 将序列化配置设置到 FastJson 配置中converter.setFastJsonConfig(config);converter.setDefaultCharset(StandardCharsets.UTF_8);// 创建一个媒体类型表示支持 JSON 格式并使用 UTF-8 编码ListMediaType fastMediaTypes new ArrayList();MediaType utf8MediaType new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8);fastMediaTypes.add(utf8MediaType);converter.setSupportedMediaTypes(fastMediaTypes);// 将 FastJson 消息转换器添加到 Spring Boot 的消息转换器列表中位置是第一个这样确保它优先于其他消息转换器converters.add(0, converter);}
http://www.zqtcl.cn/news/521812/

相关文章:

  • 做网站实例教程网站图片的作用
  • 网站建设展板营销渠道的三个类型
  • 用php做视频网站有哪些十大免费logo设计
  • 网站建设对于网络营销的意义微信购物商城
  • 基于个性化推荐的电商网站设计与实现网站 用户体验的重要性
  • 怎么用ajax做电商网站企业网查询是什么
  • 海淀企业网站建设张店学校网站建设公司
  • 专业微网站开发做购物网站怎么赚钱
  • 怎样做酒店网站ppt什么是企业网络营销平台
  • 科技部网站改版方案济南众筹网站建设
  • 中国城乡与住房建设部网站电子商务公司名字推荐
  • 设计参考网站有哪些wordpress 支付宝免签
  • 网站关键词排名优化应该怎么做外包加工网缝纫机外放加工活
  • 电影网站建设模板从传播的角度
  • 北京建网站的公司广州冼村和猎德村哪个最有钱
  • 成都网站建设有限公司济南j建设网
  • 一家网站建设公司需要什么资质互联网网站模块
  • 网站开发php支付接口网站平台建设缴纳什么税
  • 百度文库推广网站庆云网站seo
  • 全网通网站wordpress 按点击调用热门文章
  • 添加网站栏目的步骤网站需求分析怎么做
  • 做网站用那一种语言最好武邑网站建设价格
  • 哈尔滨网站制作招聘互动的网站
  • 专业网站建设品牌网站建设基础课件
  • 自学网站编程网站建设银行北京冬奥会纪念币发行时间
  • 个人网站备案需要盖章吗做网站用什么颜色好
  • 在线制作论坛网站做网站开发团队
  • 2017年网站建设工作总结dhru商城网站建设
  • 建设网站需要申请深圳的网站建设的公司
  • 教育类的网站案例门户网站建设推广