1.设置配置文件application.properties
server.port=8088
spring.mvc.view.prefix=templates/
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
spring.thymeleaf.prefix: classpath:/templates/
spring.resources.static-locations=classpath:/static/
2.设置controller
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
@Controller
@SpringBootApplication
public class TerminalApplication {
public static void main(String[] args) {
SpringApplication.run(TerminalApplication.class, args);
}
@RequestMapping("/")
public String indexHtml(HashMap<String, Object> map) {
return "/index";
}
@RequestMapping("/down")
public String downHtml(HashMap<String, Object> map) {
return "/down";
}
}
3.重启,打开浏览器http://localhost:8088 ,即可访问templates目录的index.html