天天看點

spring boot controller 擷取url

場景:如果單個接口存在多url時,想擷取目前請求的url位址

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Description: 測試
 * <p>
 * Author: yli
 * CreateDate: 2020-12-10 19:00
 */
@RestController
public class TestController extends ControllerSupport {

  @Autowired
  private HttpServletRequest request;

  @PostMapping(value = {"/test1", "/test2"})
  public RestResultResponse test(@RequestBody Object object) {
    request.getRequestURL();
    return restResponses.ok2(true);
  }

}