一、路由返回静态页面,却返回了静态文件的路径
解决:
1、注解使用错误
controller类的注解应该是 @Controller
而不是@RestController
前者只要返回RseonBody,后者可返回页面
2、上述设置成功,却报错,形如:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Oct 11 20:53:09 CST 2018
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="/up", line 6 - column 3
注意到最后一行,此时应该是HTML的语法出现了错误,去排除即可。可以看出我的有个地方没有闭合标签,话说,这规则也太严苛了。

本文解决了在使用Spring Boot框架时,路由返回静态页面而非预期的页面内容的问题。首先纠正了注解使用上的误区,@Controller应搭配@ResponseBody使用,而@RestController则直接用于返回页面。其次,针对HTML语法错误导致的WhitelabelErrorPage问题,提供了详细的排查方法。
路由返回静态页面,却返回了静态文件的路径&spm=1001.2101.3001.5002&articleId=83018767&d=1&t=3&u=392381efd2d8418c96c7e04b595b3b40)
1514

被折叠的 条评论
为什么被折叠?



