SpringBoot的属性配置
-
建议将application.properties换成application.yml
-
yaml通过缩进行 对齐进行表示层次关系 如下表示girl.cupSize和girl.age属性
girl: cupSize: D age: 18
*在spring的controller中使用配置文件中的属性
1 @Value("${cupSize}") 2 private String cupSize;
-
还可以在配置文件中使用配置文件中的属性 如下在context中使用了girl.age属性
girl: cupSize: D age: 18 context: "age: ${girl.age}"
controller的使用


-
PathVariable的使用:用来获取在路径中的参数 如下:
1//访问方式 http://localhost:8080/hello/110 2@RequestMapping("/hello/{id}") 3public String sayHello(@PathVariable("id") Integer id){ 4 return id+""; 5} -
GetMapping是RequestMapping注解的简写 指定了访问方法为Get 类似还有Post等