Springboot访问html

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/f1370335844/article/details/82193576

(一)没有配置thymeleaf之类的模板之前,是访问不到template目录下的文件的,但是可以将html或者其他文件放在static文件下下面是可以直接通过路径和文件名访问的,如http://localhost:8080/login.html,也可以通过controller跳转,但是必须带后缀名。

@RequestMapping("/index")
public String index(){
    return "login.html";
}

(二)配置了thymeleaf之类的模板后,通过controller跳转的方式还是可以用的,默认跳转的路径从static变成了template,这个时候,不需要带页面后缀名。同时通过直接路径访问static下的html页面的方式还是可以用的,即访问http://localhost:8080/login.html

@RequestMapping("/index")
public String index(){
    return "login";
}

参考其他大佬的文章

猜你喜欢

转载自blog.csdn.net/f1370335844/article/details/82193576