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);
    }




  • 相关阅读:
    flutter 右滑返回上一页
    flutter 的Animation简单了解
    Flutter Offstage、Visibility隐藏/可见
    flutter手势
    Flutter生命周期
    flutter 路由动画
    flutter 保持页面状态
    flutter 不规则底部工具栏实现
    flutter 主页面底部导航栏实现以及主题风格设置
    flutter DropdownButton使用
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2418754.html
Copyright © 2011-2022 走看看