解决Springboot项目中文乱码的问题

SpringBoot读取properties中文乱码解决方案 在SpringBoot开发中,我们经常会使用properies文件来配置项目的各种参数,包括中文字符,然而有时候我们会遇到properies文件中的中文字符在读取时出现乱码的情况。这种问题可能影响到我们项目的正常运行,因此需要及时解决。本文将介绍如何解决SpringBoot读取properies中文乱码问题,并提供相应的代码示例。 阅读详情

转:https://blog.csdn.net/mulinsen77/article/details/87873954/

 

  1. 首先,对于mySql连接的问题:若从前端 插入中文数据,进入数据库中出现乱码,则检查数据库的编码以及在application.properties中的连接是否设置编码为UTF-8。在这里插入图片描述
  2. 对于通过url传参,出现中文乱码的情况,需要以下几个步骤。
    在这里插入图片描述
    (1). 在application.properties中设置如下参数:
# 解决中文乱码的问题
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8

(2). 在config类中,继承自WebMvcConfigurationSupport类,重写以下方法:
(有人说是:创建国际化支持配置类)

/**
     * 解决中文乱码的问题
     * @return
     */
    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        return new StringHttpMessageConverter(Charset.forName("UTF-8"));
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(responseBodyConverter());
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false);
    }

测试的时候,发现步骤一可以省略,但是为了保险起见,我们还是按照步骤一二来。
因为有些文章中说的是,经过步骤一之后,拦截器中回来的中文现已不乱码了,可是controller中回来的数据仍旧乱码,所以才需步骤二。

测试结果如下:
在这里插入图片描述

SpringBoot项目实战:集成itextpdf动态生成PDF报表,并解决中文乱码问题 本文详细介绍了在SpringBoot项目中集成iTextPDF动态生成PDF报表的实战经验,重点解决中文乱码问题。通过环境准备、服务层设计、HTTP响应优化等步骤,提供了一套完整的解决方案,适用于电商后台、数据看板等场景,显著提升PDF生成效率。 阅读详情

相关推荐

游戏开发-GM系统的设计

游戏管理员(gm)作为游戏中拥有更高权限的账号,在游戏开发的过程中,我们需要很早的将gm系统做出来,作为测试游戏逻辑具有不可替代的作用。 内容目录 服务端与客户端通讯基本流程 gm命令格式设计 gm系统的实现 服务端与客户端通讯基本流程 服务端与客户端通信,如果基本的网络框架搭建完成,那么我们只需要写好命令就可以了 服务器完成一条命令的添加需要3个过程。 (1)命令格式的定义

微不足道 4623

解决SpringBoot返回中文乱码问题方法汇总

解决SpringBoot中文乱码问题

m0_59278919的博客 2万+

基于STM32与MPU6050的实时姿态检测系统设计与实现(源码+硬件解析)

本文详细介绍了基于STM32单片机与MPU6050传感器的实时姿态检测系统设计与实现。通过硬件解析、传感器校准、卡尔曼滤波算法和欧拉角计算,实现高精度姿态检测。提供完整源码和调试技巧,适用于无人机、平衡车等嵌入式开发项目,解决噪声干扰和数据漂移等常见问题。

jupi8的博客 500

SpringBoot中文乱码问题解决方案

在Spring Boot中,确实没有像传统Web应用程序中需要使用web.xml配置文件。如果以上方法仍无法解决你的问题,可以尝试在控制器层对请求和响应进行编码设置。这个依赖会引入Tomcat的字符编码过滤器,有助于解决中文乱码问题。通过在请求和响应对象上设置字符编码,确保数据传输的正确性。这里将字符集设置为UTF-8,并启用了HTTP编码配置。

sync_with_U 7409

新年美食鉴赏——基于注意力机制CBAM的美食101分类

新年美食鉴赏——基于注意力机制CBAM的美食101分类一、数据预处理1.数据集介绍2.读取标签3.统一命名4.整理图片路径5.划分训练集与验证集6.定义美食数据集二、注意力机制1.简介2.卷积块注意力网络——CBAM通道注意力模块CAM空间注意力模块SAM3.将通道、空间注意力模块合并三、基于卷积块注意力模块的ResNet-CBAM1.代码实现2.模型测试3.查看网络结构4.模型训练5.模型预测四、总结与升华个人简介 春节是一年当中最隆重、最盛大的节日,吃得最好的一餐可能就是年夜饭了,想想就很激动呢!随着新

zbp_12138的博客 1万+

MFC使用Websocket通讯介绍和实例(附完整源码)

踩坑点,下载了好几个boost版本编译,经常出问题,后来搜索了好久资料才发现如下评论:WebSocket++0.8.2 has been tested through Boost 1.72。WebSocketpp依赖于boost,因此在使用WebSocketpp前需要编译Boost;所以我们直接下载Boost 1.72的windows版的进行安装,安装完成还需要编译;WebSocketpp也叫WebSocket++;服务编译好之后,使用。

weixin_42530684的博客 1173

Spring Boot 中文乱码问题解决方案汇总

最近在公司项目当中 升级了Springboot 版本 出现一点小问题(乱码了) 访问地址 本文当中使用是httpClient 测试 ### GET http://localhost:8081/ebook/list?pageNum=1&pageSize=10000 Accept: application/json 结果为 跑起来后 发现乱码了 就去百度了一下 后面发现百度上说的都设置还是没有效果 不知道是不是自己傻 没有找到对应文章 经过自己研究和看文档 有2种方式可以解决...

热爱码农的平民博客 1万+

【即插即用模块】Transformer篇 | CVPR 2025 | SADA:多尺度+可变形采样,完美替换自注意力实现涨点!

文章摘要 本文提出了一种尺度自适应可变形注意力模块(SADA),用于处理图像修复中的结构化伪影问题。SADA通过多尺度多头机制捕获远程依赖关系,并引入可变形采样偏移来有效处理非均匀空间分布的模式。该模块适用于底层视觉任务,可替代ViT自注意力,实验证明能显著提升性能。代码已开源,支持即插即用集成。 核心特点: 多尺度头适应不同大小的重复模式 可变形偏移优化非均匀分布采样 轻量级设计,易于集成到现有架构 适用场景:图像去噪、超分辨率等底层视觉任务。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1436

SpringBoot几种中文乱码解决办法

1.直接返回中文字符串乱码 比如下面这段代码: @RequestMapping(value = "/upload") public String upload(@RequestParam("file1") MultipartFile file) { if (file.isEmpty()) { return "文件为空"; } ...

chinoukin的博客 7698

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

WW、forever的博客 494

《Python入门到精通》函数详解

函数就是一段「封装」起来的「代码」,目的是提高代码的「模块性」和「复用性」。 2、函数的参数 2.1、变量的就近原则 2.2、传递参数 2.3、形参和实参 2.4、位置参数 2.5、缺省参数 2.6、可变类型和不可变类型 2.7、关键字参数 3、匿名函数 4、函数的返回值

wangyuxiang946的博客 1万+

springboot项目中文件的下载(解决中文乱码问题)

最近使用springboot项目,一直以来文件都以英文格式存储,这次使用的是xls文件下载,文件名为中文的,特此记录下中文文件名的下载以及springboot中下载路径报错问题。 正文 在使用springboot导出excel的时候,出现了两个问题:如下 1. 导出的时候中文名乱码问题 如:鑱旂綉鍗煎叆妯℃澘.xlsx 2. 导出的时候springboot路径问题:在jar项目后会默认多...

weixin_33775572的博客 1万+

姿态传感器/陀螺仪之BMI270应用原理图设计

BMI270是一款由博世(Bosch)推出的高性能、超低功耗惯性测量单元(IMU),专为可穿戴设备、智能设备及物联网应用设计。

corlin6688的博客 2879

Spring Boot项目读取yml文件中值为中文时,在视图页面显示乱码问题解决

在Spring Boot项目中,我们会遇到在yml配置文件中有放中文值的属性,在取这种中文值放到页面上面展示的时候,会出现页面中乱码的情况。 遇到因为取yml中文在页面上显示乱码这种情况,我们重新设置编码工具的编码方式就ok了。 找到IDEA的Settings中的File Encodings,将图中标红的配置都统一设置为UTF-8,最后点击Apply应用和ok。 这...

Apollo 8898

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

解决Spring Boot项目中配置文件application.properties中文乱码问题

独孤欢颜的博客 1614

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

SpringBoot项目解决全局响应返回中文乱码问题

一、问题   新建的基于SpringBoot的MVC项目,在请响应体中,如果有中文,会显示为乱码。 二、解决方案 1、在application.properties中设置: spring.http.encoding.force=true spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=t...

a616735104的博客 4586

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring boot 2项目部署到Windows系统tomcat中遇到中文乱码问题(都是问号?)解决记录...

开发环境: macOS Mojave 10.14.4; java 1.8; IDEA 2019.1; tomcat 8.5; mysql 5.7. 复制代码 开发框架 spring boot2 mybatis 复制代码 统一编码 UTF-8 复制代码 场景描述 开发一个接收数据的接口,用于接收数据并插入到数据库。 请求方式POST请求,Content-Type:application/json ...

weixin_33964094的博客 2187

解决spring boot项目读取yml配置文件的中文字符,视图显示乱码的问题

解决spring boot项目读取yml配置文件的中文字符,视图显示乱码的问题

mhx123456789的博客 175

解决Spring Boot项目后端接口返回数据中文乱码问题

摘要 解决 Spring Boot 项目中,后端返回前端的结果出现中文乱码的问题。   这几天在使用 Spring Boot 学习AOP原理的时候,通过浏览器访问后端接口的时候,响应报文总是出现中文乱码问题,为了解决这个问题,这里给出两种解决方案。 方案一:properties文件中配置字符编码格式(强烈推荐) properties文件中加入...

chenzhao635的专栏 5717

springboot项目解决返回字符串中文乱码问题

前言       前一段时间对接第三方有赞云,公司让单独开发一项目来对接同步数据,快速开发当然选择springboot了,但项目开发过程中,调试,发现页面提示框中的提示信息乱码了,才想起来,后台直接返回String类型了,但是没有并没有配置String的消息转换器,导致乱码了。 配置字符串的消息转化器解决问题: import org.sp...

keller的博客 3138

Spring Boot项目用Postman请求接口时中文乱码问题解决

Spring Boot项目用Postman请求接口时中文乱码问题解决

yfjr 3526

解决Springboot项目里调用RestTemplate中文乱码问题

/** * 解决restTemplate调用乱码 * @param restTemplate */ public static void reInitMessageConverter(RestTemplate restTemplate){ List&lt;HttpMessageConverter&lt;?&gt;&gt; converterList=restTemplate.getM...

一天过去不会再来 2789
上一篇: 从OncePerRequestFilter的源码解读去了解Spring内置的Filter的特别之处以及常见过滤器使用介绍
下一篇: maven介绍以及仓库配置pom.xml中repositories属性的意义
fgfvmiygse
博客等级 码龄12年 42粉丝 25原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值