Receive the HTTP status after a request with Spring MVC

前端 未结 2 1582
醉酒成梦
醉酒成梦 2021-01-19 11:41

i\'m sending data to a server and i want to receive the HTTP response status in order to check this status and provide the appropriate view

   @RequestMappin         


        
2条回答
  •  [愿得一人]
    2021-01-19 12:19

    What's wrong with:

    HttpStatus status = result.getStatusCode();
    if(status == HttpStatus.OK)
    

    See: ResponseEntity JavaDoc.

    BTW you should not compare strings using == operator like here:

    status=="OK"
    

    Instead use the following idiom:

    "OK".equals(status)
    

    Also method names in Java tend to start with lower case.

提交回复
热议问题