1. 程式人生 > >後臺學習筆記(一)——Springboot

後臺學習筆記(一)——Springboot

1. 網路請求訪問路徑:

server.port=8080
server.context-path=/demo-app

2. 獲取header中的token:

@RequestHeader("token") String token

如:
@PostMapping("/saveApply")
public CommonResponse saveApply(@RequestBody ApplyRequest request, @RequestHeader("token") String token) {...}

 

3. 配置變數:

@Configuration
@ConfigurationProperties(prefix = "dev.test")
public class TestConfiguration {

    private String host;

    private String business;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getBusiness() {
        return business;
    }

    public void setBusiness(String business) {
        this.business = business;
    }
}

application-local.properties配置檔案中:

server.port=8080
server.context-path=/test-app

dev.test.host=http://xxx.xx.xxx.xxx:10018
dev.test.business=/test-app/business

使用:

@Autowired
private TestConfiguration testConfig;

testConfig.getHost();即可