美文网首页
SpringBoot 自定义 Response Headers

SpringBoot 自定义 Response Headers

作者: YUNDONG丶 | 来源:发表于2019-11-30 16:55 被阅读0次
    package me.yundongis.linkblogservice.controller;
    
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpStatus;
    import org.springframework.http.ResponseEntity;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloController {
    
        @GetMapping("/hello")
        public ResponseEntity<Object> hello(){
            HttpHeaders httpHeaders = new HttpHeaders();
            httpHeaders.add("Content-Length","11");
            // 参数1:返回的包体  参数2:返回的 Headers  参数3:状态码
            return new ResponseEntity<>("hello,worlds!",httpHeaders, HttpStatus.OK);
        }
    
    }
    
    

    扩展内容
    github
    个人博客

    相关文章

      网友评论

          本文标题:SpringBoot 自定义 Response Headers

          本文链接:https://www.haomeiwen.com/subject/vawowctx.html