1.种配置文件区分

2.格式转化的网站

3.使用(application.properties中编写)
3.1 配置端口号、项目名字、公共前缀
server.port=8081
spring.application.name=first-spring-boot
server.servlet.context-path=/first
3.2 测试效果

4.配置自定义属性(application.properties中编写)
4.1 需求

4.2 编写PropertiesController.java和application.properties
package com.imooc.springbootlearn.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 描述: 和配置相关的Controller
*/
@RestController
public class PropertiesController {
@Value("${school.grade}")
Integer grade;
@Value("${school.classnum}")
Integer classnum;
static Integer age;//静态变量的值需要使用set方法赋值
@GetMapping("/gradeclass")
public String gradeClass() {
return "年级:" + grade + " 班级:" + classnum;
}
@GetMapping("/static")
public String staticPara() {
return "静态变量的值:" + age;
}
@Value("${school.age}")
public void setAge(Integer age) {
PropertiesController.age = age;
}
}
server.port=8081
spring.application.name=first-spring-boot
server.servlet.context-path=/first
school.grade=3
school.classnum=7
school.age=17