【发布时间】:2018-01-02 15:52:38
【问题描述】:
我已经写了一个基于 Spring MVC 的控制器。
@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/”有什么区别?
【问题讨论】:
-
嗯,不同之处在于您将
/的末尾映射到函数service()和@RequestMapping(value="/",method=RequestMethod.GET),而末尾没有/的URL 被映射为空。如果你调用一个 url,其余的 api 没有分配给你,自然会得到 404。
标签: java spring spring-mvc tomcat server