我写了一个基于Spring MVC的控制器。“http:// localhost/app/hello”和“http:// localhost/app/hello /”有什么区别?
@Controller
@RequestMapping("/hello")
public class JsonController {
@RequestMapping(value="/",method=RequestMethod.GET)
@ResponseBody
public Person service(){
Person person=new Person();
person.setId(3);
person.setName("666");
return person;
}
当我访问“http://localhost/app/hello”时,我得到404; 当我访问“http://localhost/app/hello/”时,我得到202 OK。 “http://localhost/app/hello”和“http://localhost/app/hello/”有什么区别?
那么不同的是,你映射了'/'用'@RequestMapping(value =“/”,method = RequestMethod.GET)'结束函数'service()',而末尾没有'/'的URL映射为空。如果你调用一个url,其余的api没有分配给你,那么你自然会得到一个404。 – Nico