簡體   English   中英

如何在Spring中返回完全空的響應

[英]How to return completely empty response in Spring

我有一個Spring MVC Rest控制器,其中URL映射之一是:

myhost:8080/helloworldexample/testnullresponse

現在,當我調用此URL時,是否可能什么也不返回

什么都沒有:沒有主體,沒有響應,沒有狀態碼,根本什么都沒有,就像服務器在聽請求一樣,什么也沒做。

我將不勝感激。 我嘗試了以下選項,但沒有任何效果:

 return new ResponseEntity<Void>(null);

    @RequestMapping(value = "/helloworldexample/testnullresponse", produces = "application/json; charset=UTF-8", method = RequestMethod.GET)
  public void nullResponse(HttpServletRequest request) {
        }

實際上,您控制器的方法可能返回void。 這是一個例子

@RequestMapping(value = "/helloworldexample/testnullresponse", method = RequestMethod.HEAD)
public void nullResponse(HttpServletResponse response) {
...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM