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

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:internalresourceviewresolver explanation

2: Configure static resources automatically

This article is "Edith accompany you learn series-Framework learning Spring Boot Framework Learning" in the sixth Spring Boot framework Learning 6-spring Boot Web Development (2)

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

One: Internalresourceviewresolver explanation

Internalresourceviewresolver (key) What is this?

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 3197c2f8ffc911f7993708368e8b8da0x781x174x6.png;,3,jpegx;3,700x.jpg "class=" image-loaded "alt=" 3197c2f8ffc911f7993708368e8b8da0x781x174 "/>


From the source we see the use of the @bean note is a relative to spring, this is a bean ld. So what is this? What role does it have? Why is the point?

Let's look at the configuration of the view parser in the MVC configuration file when using Spring MVC:

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 20b1ded7bac62f08564cdca3fd1c53eax930x336x15.png;,3,jpegx;3,700x.jpg "alt=" 20b1ded7bac62f08564cdca3fd1c53eax930x336 "/>


Did you see the internalresourceviewresolver?

So spring boot has been handled internally for us. and mention that piece of @conditionalonmisingbean. If you do not define spring boot, define one for us.

Look at the file prefix suffix:

In the source code:

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 516093871ab3eedb75aca3588f3af232x948x582x18.png;,3,jpegx;3,700x.jpg "alt=" 516093871ab3eedb75aca3588f3af232x948x582 "/>


SPIRNG boot Configuration and XML configuration comparison:

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 2ff5df82a80104a8e9c46476bcdd3332x996x519x15.png;,3,jpegx;3,700x.jpg "alt=" 2ff5df82a80104a8e9c46476bcdd3332x996x519 "/>


So what if we want to define ourselves?

Remember the global configuration you learned before?

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 21f59b3361cbc0ea507f04c380e78a31x510x98x4.png;,3,jpegx;3,700x.jpg "alt=" 21f59b3361cbc0ea507f04c380e78a31x510x98x "/>


In the global configuration file, we can customize the prefix and suffix.

So then we just need to add the front and back to the global configuration.

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 900771fbd42b0892ff305fabd60a631fx485x58x2.png;,3,jpegx;3,700x.jpg "alt=" 900771fbd42b0892ff305fabd60a631fx485x58x "/>


Two: automatic configuration of static resources

2.1: Enter the rules for/

If the rule to enter SPRINGMVC is/, the path to the default static resource for Spring boot is:

spring.resources.static-locations=classpath:/meta-inf/resources/,classpath:/resources/,classpath:/static/, classpath:/public/

Test Example:

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ 99dace5130134c270fa6c7fb2fc49dffx969x303x9.png;,3,jpegx;3,700x.jpg "alt=" 99dace5130134c270fa6c7fb2fc49dffx969x303 "/>


In

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ E2836d28791e1ba6a230a6dac8dcd4dax270x157x4.png;,3,jpegx;3,700x.jpg "alt=" e2836d28791e1ba6a230a6dac8dcd4dax270x157 "/>


Access:

650) this.width=650; "Src=" http://image.uc.cn//o/wemedia/s/upload/2017/ F92f37c963c753710ab4bbd195dbad06x1211x551x26.png;,3,jpegx;3,700x.jpg "alt=" F92f37c963c753710ab4bbd195dbad06x1211x55 "/>



2.2: Enter the rule for *.xxx or pail top static file path time

You can place static resources in the static directory under WebApp and access them by address.

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)

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/55

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



This article from the "Edith Java" blog, reproduced please contact the author!

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

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.