目录
Whitelabel Error Page
出错原因
代码块
访问路劲:
代码功能
错误分析:
解决方法
建议
总结 type = Not Found:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Aug 26 16:13:05 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available
当访问getStatus() 方法时,返回type = not found。
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
http://localhost:8080/status
获取json格式的数据,此数据是关于状态码的。如:
{“code”:”404”,”message”:”错误”,”date”:1504779777036}
1. 从页面错误信息可知,not found 是指资源找不到
2. 如果想要访问getStatus()方法,那么需要在此方法上加@RequestMapping(value = “xxx”),此值可以为空,也可以有值,但必须要写此注解
3. 如上面的代码中getStatus()上并没有写@RequestMapping注解,所以会报错
方法一(添加代码 @RequestMapping(“”))
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping("")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
方法二(添加代码 @RequestMapping(value = “”))
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping(value = "")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
方法三(添加代码 @RequestMapping(value = “/hello”))
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping(value = "/hello")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
方法四(添加代码 @RequestMapping
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
当想要访问的方法并不需要url时,建议以下写法:
@RequestMapping(value = “”)
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping(value = "")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
示例1(url路劲没写正确):
当在getStatus()方法上添加注解@RequestMapping后,访问成功路劲的url和错误路劲的url会返回不同的页面,如下演示。
正确的url
http://localhost:8080/status
返回我们想看到的200成功的页面:
错误的url
http://localhost:8080/status/ddd
http://localhost:8080/stat
返回错误Not Found页面:
总结:
type=Not Found 访问的资源找不到:
1.1 可能是你的url路劲没写正确
1.2 可能是后台代码的@RequestMapping没写
1.3 可能路劲中包含中文字符,如中文的问号?, 中文的逗号,
如:Whitelabel Error Page之 Not Found