Article directory
About static resources
- As long as the static resources are placed in the classpath: called /static (or /public or /resources or /META-INF/resources
Access: current project root path / + static resource name
Principle: static mapping /**. - When a request comes in, first go to the Controller to see if it can be processed. All requests that cannot be processed are handed over to the static resource handler. If the static resource is not found, it will respond with a 404 page
As an example
Put a cute rice cooker in the static
Visited,
let's write a controller
We ca n't access it.
We can see that the priority of our controller is higher than that of static resources.
Why are our default resource paths like these?
called /static (or /public or /resources or /META-INF/resources
Let's take a look at the source code
. This is too long. I cut a part and we can see that these are written in the source code.
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{
"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"};
So there is a question, where can we customize the static ones?
Of course, is
n't this annotation to read the core configuration file?
Let's customize it in the configuration file
Let's talk about the following
spring:
mvc:
static-path-pattern: /res/**
This is the static resource access prefix
Current project + static-path-pattern + static resource name = search under the static resource folder
Because we have configured it to be found under /res/, so we need to add the following under the path.
Of
course, we can add it A lot of folders
can be added like this
A story about the welcome page
Look at what the official documentation says, it
probably means:
- springboot supports static mode and template mode
- If it is a static method, the file named index.html will be regarded as the welcome page, which is the page we will jump to when we visit the root directory.
- If the index is not found, html springboot will go to the controller to find the index request and then jump to that page
Static welcome page
Before we set up static resources to be placed under /gb/ and /gb1/
Let's put the index page under /gb/ Let
's access the root path address
Change the page icon
what is the icon
this is the icon
how to change
It means that you can change the name of the icon you want to change to this and put it in the static resource.
Just use my avatar. The
wise avatar has been placed and pinched.
If you succeed, you can see my wise avatar.
Why do I have to switch browsers to access
Because the browser reads the icon is shared in a session, the
browser will not change if the session is not closed,
directly changing the browser is equivalent to a new session