久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <i id='pS1CM'><tr id='pS1CM'><dt id='pS1CM'><q id='pS1CM'><span id='pS1CM'><b id='pS1CM'><form id='pS1CM'><ins id='pS1CM'></ins><ul id='pS1CM'></ul><sub id='pS1CM'></sub></form><legend id='pS1CM'></legend><bdo id='pS1CM'><pre id='pS1CM'><center id='pS1CM'></center></pre></bdo></b><th id='pS1CM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pS1CM'><tfoot id='pS1CM'></tfoot><dl id='pS1CM'><fieldset id='pS1CM'></fieldset></dl></div>

  2. <legend id='pS1CM'><style id='pS1CM'><dir id='pS1CM'><q id='pS1CM'></q></dir></style></legend>
  3. <small id='pS1CM'></small><noframes id='pS1CM'>

    1. <tfoot id='pS1CM'></tfoot>
        <bdo id='pS1CM'></bdo><ul id='pS1CM'></ul>
    2. Spring中的@RequestBody和@ResponseBody注解

      @RequestBody and @ResponseBody annotations in Spring(Spring中的@RequestBody和@ResponseBody注解)

          1. <legend id='NGN3v'><style id='NGN3v'><dir id='NGN3v'><q id='NGN3v'></q></dir></style></legend>
              <bdo id='NGN3v'></bdo><ul id='NGN3v'></ul>

                <i id='NGN3v'><tr id='NGN3v'><dt id='NGN3v'><q id='NGN3v'><span id='NGN3v'><b id='NGN3v'><form id='NGN3v'><ins id='NGN3v'></ins><ul id='NGN3v'></ul><sub id='NGN3v'></sub></form><legend id='NGN3v'></legend><bdo id='NGN3v'><pre id='NGN3v'><center id='NGN3v'></center></pre></bdo></b><th id='NGN3v'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NGN3v'><tfoot id='NGN3v'></tfoot><dl id='NGN3v'><fieldset id='NGN3v'></fieldset></dl></div>
                <tfoot id='NGN3v'></tfoot>

                  <tbody id='NGN3v'></tbody>
              • <small id='NGN3v'></small><noframes id='NGN3v'>

              • 本文介紹了Spring中的@RequestBody和@ResponseBody注解的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                有人能解釋一下 Spring 3 中的 @RequestBody@ResponseBody 注釋嗎?它們是干什么用的?任何例子都會(huì)很棒.

                Can someone explain the @RequestBody and @ResponseBody annotations in Spring 3? What are they for? Any examples would be great.

                推薦答案

                文檔中有一個(gè)完整的Section,叫做16.3.3.4 用@RequestBody注解映射請(qǐng)求體.還有一個(gè)叫做 16.3.3.5 使用@ResponseBody 注解映射響應(yīng)體.我建議你查閱這些部分.也相關(guān):@RequestBody javadocs, @ResponseBody javadocs

                There is a whole Section in the docs called 16.3.3.4 Mapping the request body with the @RequestBody annotation. And one called 16.3.3.5 Mapping the response body with the @ResponseBody annotation. I suggest you consult those sections. Also relevant: @RequestBody javadocs, @ResponseBody javadocs

                用法示例如下:

                使用 JQuery 之類的 JavaScript 庫(kù),您可以像這樣發(fā)布 JSON 對(duì)象:

                Using a JavaScript-library like JQuery, you would post a JSON-Object like this:

                { "firstName" : "Elmer", "lastName" : "Fudd" }
                

                您的控制器方法如下所示:

                Your controller method would look like this:

                // controller
                @ResponseBody @RequestMapping("/description")
                public Description getDescription(@RequestBody UserStats stats){
                    return new Description(stats.getFirstName() + " " + stats.getLastname() + " hates wacky wabbits");
                }
                
                // domain / value objects
                public class UserStats{
                    private String firstName;
                    private String lastName;
                    // + getters, setters
                }
                public class Description{
                    private String description;
                    // + getters, setters, constructor
                }
                

                現(xiàn)在,如果您的類路徑中有 Jackson(并且有一個(gè) <mvc:annotation-driven> setup),Spring 會(huì)將傳入的 JSON 轉(zhuǎn)換為來(lái)自 post body 的 UserStats 對(duì)象(因?yàn)槟砑恿?@RequestBody 注釋)并將返回的對(duì)象序列化為 JSON(因?yàn)槟砑恿?@ResponseBody 注釋).所以瀏覽器/客戶端會(huì)看到這個(gè) JSON 結(jié)果:

                Now if you have Jackson on your classpath (and have an <mvc:annotation-driven> setup), Spring would convert the incoming JSON to a UserStats object from the post body (because you added the @RequestBody annotation) and it would serialize the returned object to JSON (because you added the @ResponseBody annotation). So the Browser / Client would see this JSON result:

                { "description" : "Elmer Fudd hates wacky wabbits" }
                

                有關(guān)完整的工作示例,請(qǐng)參閱我以前的答案:https://stackoverflow.com/a/5908632/342852

                See this previous answer of mine for a complete working example: https://stackoverflow.com/a/5908632/342852

                注意:RequestBody/ResponseBody 當(dāng)然不限于 JSON,兩者都可以處理多種格式,包括純文本和 XML,但 JSON 可能是最常用的格式.

                Note: RequestBody / ResponseBody is of course not limited to JSON, both can handle multiple formats, including plain text and XML, but JSON is probably the most used format.

                從 Spring 4.x 開(kāi)始,您通常不會(huì)在方法級(jí)別使用 @ResponseBody,而是在類級(jí)別使用 @RestController,效果相同.

                Ever since Spring 4.x, you usually won't use @ResponseBody on method level, but rather @RestController on class level, with the same effect.

                這里引用官方Spring MVC 文檔:

                @RestController 是一個(gè) 組合注釋 本身就是 元注釋@Controller@ResponseBody 表示一個(gè)控制器每個(gè)方法都繼承了類型級(jí)別的 @ResponseBody 注釋,并且,因此,直接寫入響應(yīng)正文而不是視圖解析并使用 HTML 模板進(jìn)行渲染.

                @RestController is a composed annotation that is itself meta-annotated with @Controller and @ResponseBody to indicate a controller whose every method inherits the type-level @ResponseBody annotation and, therefore, writes directly to the response body versus view resolution and rendering with an HTML template.

                這篇關(guān)于Spring中的@RequestBody和@ResponseBody注解的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯(cuò)誤)
                Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語(yǔ)句 - 是“或/“和可能的?)
                Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數(shù)的三元表達(dá)式的類型是什么?)
                Read a text file and store every single character occurrence(讀取文本文件并存儲(chǔ)出現(xiàn)的每個(gè)字符)
                Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 char 原語(yǔ)?)

                • <small id='iB7vC'></small><noframes id='iB7vC'>

                  <i id='iB7vC'><tr id='iB7vC'><dt id='iB7vC'><q id='iB7vC'><span id='iB7vC'><b id='iB7vC'><form id='iB7vC'><ins id='iB7vC'></ins><ul id='iB7vC'></ul><sub id='iB7vC'></sub></form><legend id='iB7vC'></legend><bdo id='iB7vC'><pre id='iB7vC'><center id='iB7vC'></center></pre></bdo></b><th id='iB7vC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iB7vC'><tfoot id='iB7vC'></tfoot><dl id='iB7vC'><fieldset id='iB7vC'></fieldset></dl></div>

                  1. <tfoot id='iB7vC'></tfoot>

                      <tbody id='iB7vC'></tbody>
                      <legend id='iB7vC'><style id='iB7vC'><dir id='iB7vC'><q id='iB7vC'></q></dir></style></legend>
                          <bdo id='iB7vC'></bdo><ul id='iB7vC'></ul>
                        • 主站蜘蛛池模板: 亚洲午夜小视频 | 男人天堂色 | 亚洲精品一区二区三区在线观看 | 亚洲综合在线视频 | 久久久www成人免费精品 | 国产激情91久久精品导航 | 一区二区在线看 | 99久视频 | 亚洲免费精品 | 国产激情在线 | 精品欧美一区免费观看α√ | 中文字幕影院 | 国产精品视频一区二区三区 | 999久久久久久久久6666 | 一区二区三区四区电影 | 精品成人av| 伊人电影院av | 一区二区不卡视频 | 美女三区 | 激情在线视频 | 国产色婷婷精品综合在线手机播放 | 91网在线播放 | 欧美在线视频一区二区 | 国产视频不卡一区 | 人人干人人艹 | 国产精品日韩欧美一区二区三区 | 91av国产在线视频 | 久草中文在线观看 | 亚洲一区二区三区四区五区午夜 | 日本免费一区二区三区四区 | 婷婷综合| 精品粉嫩aⅴ一区二区三区四区 | 九九导航 | 免费看黄视频网站 | 亚洲精品一区二区另类图片 | 欧美午夜一区 | 久久99网站| 久久精品国产一区二区电影 | 成人二区| 亚洲精品美女在线观看 | 又黄又爽的网站 |