Use springboot:
- Creating springboot application, select the desired scene;
- springbooty default these scenes have been configured, only a small amount of configuration specified in the configuration file can be up and running;
- Write your own business logic code;
1.springboot mapping rules for static resources
@ConfigurationProperties (prefix = "spring.resources", ignoreUnknownFileds = false ) public class ResourceProperties the implements The ResourceLoaderAware { // set and parameters related to static resources, such as cache time
1. All / Webjars / **, went classpath: / META-INF / resources / webjars / find resources;
webjars: jar package in the manner of the introduction of static resources;
localhost:8080/webjars/jquery/3.3.1/jquery.js
<!-- 引入jQuery-webjar -->
<dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.4.1</version> </dependency>
2. "/ **" Any resource access current project (static resource file folder)
"the CLASSPATH: // META-INF / Resources /" , "the CLASSPATH: // Resources /" , "the CLASSPATH: // static /",
"the CLASSPATH: // public /",
"/": the current root path of the project
localhost: 8080 / xxx (static folder inside to find xxx)
3. Welcome Page: a static resource folders under index.html page all; by "/ *" Mapping;
localhost: 8080 / find index page
4. All ** / favicon.ico are looking at a static resource files;
2. The template engine
For example: jsp, Velocity, Freemaker, Thymeleaf.
springboot recommended Thymeleaf grammar simpler, more powerful;
1. The introduction of Thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2.Thymeleaf use & grammar
Thymeleaf use the document: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
The default prefix = "classpath: / templates /" Default suffix = "html."
@RequestMapping("/success") public String success(){ return "success"; }
Import Thymeleaf namespace 1.html page
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2. Use syntax Thymeleaf
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>成功!~ lol</h1> <p th:text="${hello}"/> </body> </html>
3. syntax rules
1) th: text to change the text of the current element
th: attribute value to replace any of the native attributes html
2) expression (Thymeleaf Chapter IV document)
|
4.SpringMVC automatic configuration
http://www.spring-boot.org/doc/pages/spring-boot-features.html#boot-features-json-json-b 第28节
Thymeleaf