遇到的问题:按照别人的blog搭jsp页面就是html页面跳转不了,总是如图:
终于找到了一个能用的blog ,换 thymeleaf(html页面跳转)成功。
控制器代码
注意下:
@Controller而不是@RestController,不然也会直接返回字段值
不然就变成入门(一)写的内容
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloController { @RequestMapping("/test") public String test(){ return "login"; } }
html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Title</title> </head> <body> <h1>1314314141</h1> </body> </html>
application.properties 配置文件
server.port=8000
#spring mvc
spring.thymeleaf.prefix=classpath:/templates/
项目文件截图
注意
html的位置被放错
最后 http://127.0.0.1:8000/test 访问到(在配置文件中指定了下端口号8000)
于是~愉快得访问到页面啦~~~
疑问可参考下blog ~~ https://blog.csdn.net/Sicily_winner/article/details/78985187