REST_返回形式
Posted rocker-pg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了REST_返回形式相关的知识,希望对你有一定的参考价值。
摘录:
"Web resources" were first defined on the World Wide Web as documents or files identified by their URLs. However, today they have a much more generic and abstract definition that encompasses every thing or entity that can be identified, named, addressed, or handled, in any way whatsoever, on the web. In a RESTful web service, requests made to a resource‘s URI will elicit a response that may be in XML, HTML, JSON, or some other format. The response may confirm that some alteration has been made to the stored resource, and the response may provide hypertext links to other related resources or collections of resources. When HTTP is used, as is most common, the operations available are GET, POST, PUT, DELETE, and other predefined CRUD HTTP methods.
- 返回HTML格式的响应
1 @Controller 2 //@RestController 3 public class RestDemo { 4 5 /** 6 * 这里返回html 7 * path和value属性可以在org.springframework.web.bind.annotation.RequestMapping看到 8 * 这两个属性互相为别名 9 * 且这两个属性都是数组,可以放多个可能的值 10 * 从spring4.3引入了GetMapping接口,简化RequestMapping对get请求的处理 11 * @RestController = @Controller + @ResponseBody() 12 */ 13 //@RequestMapping(value={"/html/demo","/html/demo2"}) 14 //@RequestMapping(path={"/html/demo","/html/demo2"}) 15 @GetMapping(value={"html/demo3","html/demo4"}) 16 @ResponseBody() 17 public String htmlCode(){ 18 return "<html><body>hello world</body></html>"; 19 } 20 }
以上是关于REST_返回形式的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Spring Boot Rest API 中以 XML 形式返回对象列表