Java springboot访问templates的html和静态资源

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

发布了94 篇原创文章 · 获赞 42 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/89399649