小飞知识库 | YeLu🤠MiLu🤪 小飞知识库 | YeLu🤠MiLu🤪
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

YeLu

爱技术的YeLu🤠
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 函数式编程

  • spring

  • springMVC

  • springCloud

  • jvm

  • JUC并发编程

  • mybatis

  • 设计模式

  • 📒springBoot

    • springboot介绍

      • springboot介绍
      • 全局配置问题
      • Starter POM
      • 常规的Web配置
        • 配置消息转换器(方式一)
        • 配置消息转换器(方式二)
      • 自动配置示例
      • 研究下yaml格式的语法
      • 开发模式
    • springboot源码分析

    • springboot整合三方框架

    • 📒实用干货

  • 单元测试

  • java
  • 📒springBoot
  • springboot介绍
YeLu🤠
2024-12-26
目录

常规的Web配置

# 配置消息转换器(方式一)

// @Configuration
@SpringBootConfiguration //在springboot中建议使用这个注解 替换 @Configuration
@ComponentScan(basePackages = {"com.xf.springboot"})//spring包的扫描
public class AppConfig {
    /**
     * 消息转换器
     * ISO-8859-1 这个是欧洲人的编码
     * @return
     */
    @Bean
    public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
        FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
        // fastJsonHttpMessageConverter.setDefaultCharset(Charset.forName("ISO-8859-1"));欧洲人的编码
        fastJsonHttpMessageConverter.setDefaultCharset(StandardCharsets.UTF_8);
        return fastJsonHttpMessageConverter;
    }

    /**
     * 字符串类型的消息转换器
     * @return
     */
    @Bean
    public StringHttpMessageConverter stringHttpMessageConverter() {
        // return new StringHttpMessageConverter(Charset.forName("ISO-8859-1"));
        return new StringHttpMessageConverter(StandardCharsets.UTF_8);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# 配置消息转换器(方式二)

@SpringBootConfiguration
public class AppConfig1 extends WebMvcConfigurerAdapter {
    /**
     * 添加消息转换器
     *
     * @param converters
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
        fastJsonHttpMessageConverter.setDefaultCharset(StandardCharsets.ISO_8859_1);
        /**
         * 这个表示对返回字符串的编码
         */
        // StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
        // stringHttpMessageConverter.setDefaultCharset(Charset.forName("ISO-8859-1"));
        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.ISO_8859_1);

        converters.add(stringHttpMessageConverter);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
最近更新: 2024/12/26, 17:36:00
Starter POM
自动配置示例

← Starter POM 自动配置示例→

最近更新
01
服务端配置
07-30
02
frp 安装
07-30
03
Prometheus采集Springboot应用
02-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | YeLu🤠MiLu🤪 | MIT License 蜀ICP备2024116879号 | 川公网安备51012202001998号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
欢迎你,我的朋友
看板娘