@PathVariable获取url中的数据
@RequestParam获取请求参数的值
@GetMaping组合注解,是@RequestMapping(method=GET)的缩写
@RestController
public class Controller {
@RequestMapping(method = GET, value="/hello/{id}/{name}")
public String sayHello(@PathVariable("id")Integer id, @PathVariable("name") String name) {
return "id:" + id + " name:" + name + "\n";
}
@GetMapping("/helloworld")
public String helloWorld() {
return "helloWorld";
}
@RequestMapping(method=GET, value="/greeting")
public String greetingFunc(@RequestParam(value="name", defaultValue = "World") String name) {
return "name " + name;
}
}
网友评论