zoukankan      html  css  js  c++  java
  • [springmvc]Generating responses

    1. Return a POJO annotated with @ResponseBody: POJO marshaled as the body of the response

        @RequestMapping(value="/response/annotation", method=RequestMethod.GET)
    public @ResponseBody String responseBody() {
    return "The String ResponseBody";
    }

    @RequestMapping(value="/response/charset/accept", method=RequestMethod.GET)
    public @ResponseBody String responseAcceptHeaderCharset() {
    return "こんにちは世界! (\"Hello world!\" in Japanese)";
    }

    @RequestMapping(value="/response/charset/produce", method=RequestMethod.GET, produces="text/plain;charset=UTF-8")
    public @ResponseBody String responseProducesConditionCharset() {
    return "こんにちは世界! (\"Hello world!\" in Japanese)";
    }

    2. Return a new ResponseEntity<T> object

        @RequestMapping(value="/response/entity/status", method=RequestMethod.GET)
    public ResponseEntity<String> responseEntityStatusCode() {
    return new ResponseEntity<String>("The String ResponseBody with custom status code (403 Forbidden)",
    HttpStatus.FORBIDDEN);
    }

    @RequestMapping(value="/response/entity/headers", method=RequestMethod.GET)
    public ResponseEntity<String> responseEntityCustomHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    return new ResponseEntity<String>("The String ResponseBody with custom header Content-Type=text/plain",
    headers, HttpStatus.OK);
    }




  • 相关阅读:
    HDU4608+模拟
    七、cocos2dx之粒子系统
    组织机构代码校验码 验证程序
    公民身份号码 校验码 检证程序
    百度地图之短串分享
    HDU 1421 DP
    动物:黄鼬、黄鼠狼
    动物-昆虫-蜂:马蜂
    动物-昆虫-蜂:青米蜂
    动物-昆虫-蜂:土蜂
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2418754.html
Copyright © 2011-2022 走看看