注解:
@Controller 处理http的请求;
@RestController 组合注解(@Controller和@ResponseBody注解的组合);
@RequestMapping 配置url映射(因为其有时代码较长,可用@GetMapping或者@PostMapping等组合注解替代)
@PathVariable 获取url中的数据
@RequestParam 获取请求参数的值
@GetMapping 组合注解
注意:
1)@GetMapping(value=“/hello”)或者@PostMapping,设置方法的url
2)使用@RequestParam注解获取属性的值(url中),在方法体的参数前加入注解:
public Spring say(@RequestParam(value=“id”,required=false,defaultValue=“0”Integer id)){
return id;
}
其中,设置了id的默认值,即当url中,
情况一:没用传入id的值时,或者传入为null时: (如:localhost:8080/hello 或者 localhost:8080/hello?id=),会显示id:0
情况二:传入id时:
会显示出入的id的值为111(如:127.0.0.1:8080/hello?id=111)