Programmer light 2022-02-13 07:52:40 阅读数:692
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.1</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class MyApplication {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
establish templates Folder
# apply name
spring.application.name=thymeleaf
# Application service WEB Access port
server.port=8080
# THYMELEAF (ThymeleafAutoConfiguration)
# Enable template cache ( The default value is : true )
spring.thymeleaf.cache=false
# Check if the template exists , And then present
spring.thymeleaf.check-template=true
# Check whether the formwork position is correct ( The default value is :true )
spring.thymeleaf.check-template-location=true
#Content-Type Value ( The default value is : text/html )
spring.thymeleaf.content-type=text/html
# Turn on MVC Thymeleaf View resolution ( The default value is : true )
spring.thymeleaf.enabled=true
# Template encoding
spring.thymeleaf.encoding=UTF-8
# List of view names to be excluded from resolution ,⽤ Comma separated
spring.thymeleaf.excluded-view-names=
# To be lucky ⽤ Template mode above template . another ⻅ StandardTemplate-ModeHandlers( The default value is : HTML5)
spring.thymeleaf.mode=HTML5
# In the build URL Prefix before view name ( The default value is : classpath:/templates/ )
spring.thymeleaf.prefix=classpath:/templates/
# In the build URL The suffix after the view name ( The default value is : .html )
spring.thymeleaf.suffix=.html
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class IndexController {
@RequestMapping("/index")
public ModelAndView index(){
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
index
</body>
</html>
copyright:author[Programmer light],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130752394057.html