【报错】springboot thymeleaf超链接跳转 404

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sat Dec 07 20:12:22 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
 
 
错误写法1:
<a th:href="register.html">注册</a>

错误写法2:

<a href="register.html">注册</a>
正确写法:
<a th:href="@{register}">注册</a>
并且!!!!!!直接通过超链接跳转是成功不了的。
在Controller增加了后台处理方法,直接返回html:
    @RequestMapping("/register")
    public String toRegister(){
        return "register";
    }

注意:

1. 要用RequestMapping

2. application.properties中有关配置如下:

## thymeleaf
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true

猜你喜欢

转载自www.cnblogs.com/christy99cc/p/12003433.html