table of Contents
Outline
When using Springboot web development, the Boot underlying actual use is springmvc, the project added spring-boot-starter-web dependent, will provide embedded tomcat and mvc dependency, you can view the dependency tree
1. Visit WebJar resources
Web front-end using more and more of JS or CSS, such as jQuery, Backbone.js and Bootstrap. Under normal circumstances, we are of these resources are copied to the Java Web directories are managed by hand, through this way easily lead to confusion document, inconsistent versions and other issues.
WebJars that these generic front-end Web resources packaged into Java Jar package, and then help them manage Maven tools, Web resources to ensure the uniqueness of these versions, the upgrade easier. About webjars resources, there is a dedicated website https://www.webjars.org/, we can find the resources they need to on this site, add the maven-dependent, you can use those resources directly in their own projects.
direct interview
Principle process:
View jar package introduced
SpringBoot will /webjars/**
redirect access toclasspath:/META-INF/resources/webjars/**
源码如下
It is possible to use the directory localhost: 8080 / webjars / jquery / 3.3.1 / jquery.js access static resources
2. Access static resources
SpringBoot default configuration, provides several static resource directory:
/static:classpath:/static/
/public:classpath:/public/
/resources:classpath:/resources/
/META-INF/resources:classpath:/META-INF/resources/
Of course, you can specify the location of the static configuration file by spring.resources.static-locations.
3.favicon.ico icon
If there favicon.ico file in the configuration of static resource directory, SpringBoot will automatically be set to the application icon.
In the configuration file application.properites Spring Boot may be added to the configuration items spring.mvc.favicon.enabled = false disables default favicon,
4. Welcome Page
SpringBoot supports static templates and welcome page, it first looks index.html file in a static resource directory as your home is / ** mapped
No more public on the 1st java java actual project data, technical work. More importantly, the little ape is willing to be a friend you programmed the road!
Articles starting address: www.javayihao.top
No public debut: java One