There was an unexpected error (type=Not Found, status=404).
程序员文章站
2021-11-28 11:23:44
...
使用spring项目访问后台接口时返回了这个错误。
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Oct 25 17:31:57 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
后台是这样
@Controller
@EnableAutoConfiguration
@RequestMapping("/test")
public class TestController {
@RequestMapping("/testMethod")
public JSON testMethod() {
System.out.println("12345");
Map res = new HashMap();
res.put("data", 321);
return JSONObject.fromObject(res);
}
}
通过后台查看发现,请求确实收到了,但是依然报404 。最后发现是没有设置@ResponseBody。
解决方法,方法上面加上注解@ResponseBody,或者将类的注解@Controller改为@RestController。
@RestController = @Controller + @ResponseBody
修改后的代码
@Controller
@EnableAutoConfiguration
@RequestMapping("/test")
public class TestController {
@RequestMapping("/testMethod")
@ResponseBody
public JSON testMethod() {
System.out.println("12345");
Map res = new HashMap();
res.put("data", 321);
return JSONObject.fromObject(res);
}
}
或者
@RestController
@EnableAutoConfiguration
@RequestMapping("/test")
public class TestController {
@RequestMapping("/testMethod")
public JSON testMethod() {
System.out.println("12345");
Map res = new HashMap();
res.put("data", 321);
return JSONObject.fromObject(res);
}
}
上一篇: Mysql笔记(四)多表连接查询
推荐阅读
-
win10电脑遇到DNS劫持提示ERROR 404--NOT FOUND怎么解决?
-
thymeleaf 404报错:There was anunexpected error (type=Not Found, status=404).
-
使用IDEA快速构建ssm项目并快速解决遇到的常见的HTTP Status 404 – Not Found坑
-
解决Tomcat启动显示 HTTP Status 404 – Not Found 无法访问index.jsp
-
spring boot jst 模板报404 There was an unexpected error (type=Not Found, status=404).
-
There was an unexpected error (type=Not Found, status=404)---采用layui出现的问题
-
idea:springboot整合jsp出现的错误:There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp。。
-
(发送post请求报错)There was an unexpected error (type=Forbidden, status=403). Forbidden
-
springboot中unexpected error (type=Not Found, status=404)/WEB-INF/upload.jsp和No message available解决方案
-
SpringMVC 报错HTTP Status 500 - No converter found for return value of type解决方案