@RestController://返回json
@RequestMapping://配置url映射
在resources/templates中新建index.html,注意:在类前加入@Controller同时在方法返回return "index";
@RequestMapping(Value = {"/hello","/hi"},method = RequestMethod.GET)如果我们把类注释为@RequestMapping("/hello"),把方法注释为
@RequestMapping(value = "/say", method = RequestMethod.GET)这样url可以localhost://8080/hello是访问不到方法的,必须localhost://8080/hello/say
@RequestMapping(value = "/{id}/say", method = RequestMethod.GET)
public String say(@PathVariable("id") Integer myid){
return "id:" + myid;
}这样路径中的{id}可以被提取出来@RequestMapping(value = "/say", method = RequestMethod.GET)
public String say(@RequestParam("id") Integer myid){
return "id:" + myid;
}-那我们要id可以被预先设定呢?public String say(@RequestParam(value = "id",required = false, defaultValue = "0") Integer myid)@RequestMapping(value = "/say", method = RequestMethod.GET)=@GetMapping(value = "/say")
421



被折叠的 条评论
为什么被折叠?



