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格式的响应
 @Controller
//@RestController
public class RestDemo { /**
* 这里返回HTML
* path和value属性可以在org.springframework.web.bind.annotation.RequestMapping看到
* 这两个属性互相为别名
* 且这两个属性都是数组,可以放多个可能的值
* 从spring4.3引入了GetMapping接口,简化RequestMapping对get请求的处理
* @RestController = @Controller + @ResponseBody()
*/
//@RequestMapping(value={"/html/demo","/html/demo2"})
//@RequestMapping(path={"/html/demo","/html/demo2"})
@GetMapping(value={"html/demo3","html/demo4"})
@ResponseBody()
public String htmlCode(){
return "<html><body>hello world</body></html>";
}
}

  

上一篇:netty 入门


下一篇:【Hibernate步步为营】--映射合集汇总