This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Sep 07 16:27:43 CST 2017
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注解,所以会报错
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping("")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping(value = "")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
@RestController
@RequestMapping("/status")
public class StatusController {
private String username;
private String password;
@RequestMapping(value = "/hello")
public JsonResult getStatus(){
return new JsonResult("200","成功",new Date());
}
}
@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
错误的url
http://localhost:8080/status/ddd
http://localhost:8080/stat
总结:
type=Not Found 访问的资源找不到:
1.1 可能是你的url路劲没写正确
1.2 可能是后台代码的@RequestMapping没写
1.3 可能路劲中包含中文字符,如中文的问号?, 中文的逗号,
如:Whitelabel Error Page(3)之 Not Found)