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

SpringBoot 接口调用出现乱码解决 中文乱码

SpringBoot 接口调用出现乱码解决

package com.cxjg.mvc.util;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import java.nio.charset.Charset;
import java.util.List;@Configuration
public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {@Beanpublic HttpMessageConverter<String> responseBodyConverter() {StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));return converter;}@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {super.configureMessageConverters(converters);converters.add(responseBodyConverter());}@Overridepublic void configureContentNegotiation(ContentNegotiationConfigurer configurer) {configurer.favorPathExtension(false);}
}

application.properties添加一下属性

server.servlet.encoding.force=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8

或者 这个 两个 选一个

spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8

springboot 接口加的 主要加了 一个这个 produces = “application/json;charset=utf-8”

  @PostMapping(value = UrlConstant.FIl_ies, produces = "application/json;charset=utf-8")
http://www.lryc.cn/news/129001.html

相关文章:

  • JDBC封装与设计模式
  • 小程序扫描二维码获取网址,通过Jsoup进行解析
  • Kubernetes+EFK构建日志分析平台
  • 客服如何减轻工作压力?浅析客服压力管理方法
  • 知识储备--基础算法篇-二分搜索
  • 【MySQL系列】表内容的基本操作(增删查改)
  • docker搭建LNMP
  • 未出现过的最小正整数
  • 易服客工作室:WordPress是什么?初学者的解释
  • 2019年9月全国计算机等级考试真题(C语言二级)
  • LLaMA模型泄露 Meta成最大受益者
  • 企业中商业智能BI,常见的工具和技术
  • item_password-获得淘口令真实url
  • 基于SOLIDWORKS配置功能建立塑料模具标准件库
  • 1.物联网LWIP网络,TCP/IP协议簇
  • 拷贝公钥文件后,ssh 服务器仍提示输入密码
  • 算法|Day45 动态规划13
  • 基于随机森林的手写体数字识别,基于RF的手写体数字识别,基于RF的MNIST数据集分类识别
  • vite初始化vue3项目(配置自动格式化工具与git提交规范工具)
  • leetcode473. 火柴拼正方形(回溯算法-java)
  • git-fatal: No url found for submodule path ‘packages/libary‘ in .gitmodules
  • Android开发之性能优化:过渡绘制解决方案
  • Wireshark 抓包过滤命令汇总
  • 配资平台app(正规股票配资软件)架构是怎么搭建的?
  • 【实用黑科技】如何 把b站的缓存视频弄到本地——数据恢复软件WinHex 和 音视频转码程序FFmpeg
  • 神经网络基础-神经网络补充概念-57-多任务学习
  • CMake教程6:调用lib、dll
  • 行业资讯丨“燃气智慧化”到底是什么?
  • angular注入方法providers
  • Git提交规范指南