Spring boot出现Whitelabel Error Page 的解决办法
今天帮小朋友看一个spring boot的问题,出现以下错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 02 00:33:28 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Could not get HttpServletRequest URI: Illegal character in path at index 22: http://127.0.0.1:8080/[{"msg":"登录失败","code":"0","url":"/Index"}]
出现这个问题的原因可以在这句话中得到提示:
Could not get HttpServletRequest URI: Illegal character in path at index 22: http://127.0.0.1:8080/[{"msg":"登录失败","code":"0","url":"/Index"}]
本程序的意图是输出一个字符串,但是整个框架却按照uri资源组寻找。查了一下资料后发现,spring boot 在使用@Controller以及在方法上使用@requestmapping
作为标签的时候,默认输出就是一个uri的资源定位(即跳转路径)。
那么解决就是在需要单独输出的地方使用标签:@responsebody
,这个标签用来声明将返回的字符串或者对象,写入response中的body进行返回。
更多详情请阅读文章:浅谈@RequestMapping @ResponseBody 和 @RequestBody 注解的用法与区别
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。