Asp.net网页API IHttpActionResult springboot相当于Java

问题描述 投票:0回答:1

您好我在springboot新的,我想发展springboot REST API。在用于在同一时间返回实体和httpstatuscode的.NET Web API IHttpActionresult类型,有没有在春季启动任何等效

spring-boot spring-mvc spring-web
1个回答
0
投票

使用Spring's Class ResponseEntity<T>。它允许你添加一个对象和一个响应状态,并发送给用户。从ResponseEntity docs例如:

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(location);
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);

你看ResponseEntity如何接受响应作​​为第一个参数,响应作为第二和第三HTTP状态的标头的身体。

© www.soinside.com 2019 - 2024. All rights reserved.