Spring Boot Framework Learning 7-spring Boot Web Development (3)-Custom message converters

Source: Internet
Author: User

The main contents of this chapter:

With previous learning, we learned and quickly completed the first spring boot application. Spring Boot Enterprise Framework, then how does spring boot read static resources? such as JS folder, CSS files and png/jpg pictures? How do I customize a message converter? How do I customize the configuration of spring MVC? These are all we need in the company. How do we solve this? This is explained in detail in the next section. Okay, now open the Spring Boot Web Development Section

This section mainly:

1: Custom Message Converters

This article is "Edith accompany you learn series-Framework learning Spring Boot Framework Learning" in the seventh Spring Boot Framework Learning 7-spring Boot Web Development (3)-Custom message Converter

Disclaimer: This article is Edith Java (www.kaigejava.com) original, without permission, no reprint!

One: Custom message Converters

1.1: What is a message converter capable of?

The most common is to set the encoding format.

1.2: Custom message Converters How do I get to the spring container?

To customize the message converter, simply add the message Converter's @bean to the spring container in the @configuration class, and it will be automatically added to the container by spring boot.

code example:

@Bean

public Stringhttpmessageconverter Stringhttpmessageconverter () {

stringhttpmessageconverter converter = new Stringhttpmessageconverter (

charset.forname ("UTF-8"));

retur n Converter;

/td>

What is 1.3:stringhttpmessageconverter?

Review at the time of the XML configuration:

650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ B0dcaf43889a05b59b1659e260a77087x788x242x8.png "alt=" b0dcaf43889a05b59b1659e260a77087x788x242 "/> See it? is set to encode.

To test the spring boot default encoding format:

650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ Fc6c3791bf62b6d19b52f7a31f1085b7x458x104x4.png "alt=" fc6c3791bf62b6d19b52f7a31f1085b7x458x104 "/>

Think: What is the Chinese that is returned from the interface above? Is it garbled?

Run View: '

650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ E47162d9ed04232ed9610b458efe331cx381x135x6.png "alt=" e47162d9ed04232ed9610b458efe331cx381x135 "/>

Does not garbled, the spring boot default encoding format is Utf-8.

By customizing the message converter, the encoding is modified to iso-8859-1 after it is run.

650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 67dcb2b3d1c4285726f45f443f269ca1x315x112x5.png "alt=" 67dcb2b3d1c4285726f45f443f269ca1x315x112 "/>

View Spring boot default configuration via Source:

650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ Daa42cd07c1b366bf1d7be8d1d1fb2a9x1227x270x14.png "alt=" daa42cd07c1b366bf1d7be8d1d1fb2a9x1227x27 "/> Summary:

In this section, we are primarily learning how to configure a custom message converter.

Next: In the next lesson, we will explain the configuration of the custom spring MVC. For example, if you want to add an interceptor, the user is not logged in and not allowed access.

Other articles in this series:

Spring Boot Framework Learn the important annotations of preschool mastery (1)-spring Java configuration method

Spring Boot Framework Learn important annotations for preschool Mastery (2)-Configure with Java configuration spring

Spring Boot Framework Learn important notes for preschool mastery (3)-read external resource profiles by annotation

Spring Boot Framework Learn important notes for preschool mastery (4)-read external resource profiles by annotation 2

Spring Boot Framework Learning 1-Understanding Spring boot and QuickStart

Spring Boot Framework Learning 2-spring boot core (1)

Spring Boot Framework Learning 3-spring boot core (2)

Spring Boot Framework Learning 5-spring Boot Web development (1)

Spring Boot Framework Learning 6-spring Boot Web Development (2)

Pring Boot Framework Learning 7-spring Boot Web Development (3)-Custom message converters

Welcome to the Gothic public: Edith Java

Welcome to visit Edith Personal website: www.kaigejava.com

The source of this article: HTTP://WWW.KAIGEJAVA.COM/ARTICLE/DETAIL/56

Spring Boot Series Tutorial Address: http://kaigejava.com/article/list?cateid=3



Spring Boot Framework Learning 7-spring Boot Web Development (3)-Custom message converters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.