当前位置:网站首页>@Summary of ResponseBody annotation
@Summary of ResponseBody annotation
2022-07-25 04:26:00 【Hua Weiyun】
[email protected] The role of annotations
@ResponseBody yes spring The annotations in , The annotation has no parameters ,@ResponseBody The main function of annotation is to Controller The method returns the object , After converting to the specified format through the converter , Write to HTTP response body in , Usually used to return JSON Data or xml data .
[email protected] Where is it used
@ResponseBody Annotations are generally used in Controller On the way ; It can also be used throughout Controller On , On behalf of the entire Controller The methods in @ResponseBody To convert data , If it works on the whole Controller You can talk to @Controller The annotations are merged into @RestController Annotation to use .
@ResponseBody Annotations will also play ajax Request the function of the end identifier , When ajax The request will not end until the annotation is obtained from the stream , Continue to run the program downward .
[email protected] Analysis of annotation
Used in method @RequestMapping When annotating , The return value of the method usually resolves to the path of the jump , That is, you need to jump to the specified page . When added @ResponseBody After this annotation , It indicates that the return value of this method is written directly to HTTP Response Body in [email protected] You can label any object , from Srping Complete the conversion of objects and protocols .
If the input parameter is a string, write the string directly to the client , If the input parameter is an object , The object is converted to json The string is then written to the client . What needs to be noted here is , If you return an object , Press utf-8 code . If you return String, Press default iso8859-1 code , The page may be garbled . Therefore, in the annotation, we can manually modify the encoding format , for example @RequestMapping(value="/cat/query",produces="text/html;charset=utf-8"), In front of this is the requested path , Followed by the encoding format .
@ResponseBody Let in the annotation Controller The return value of the control layer method is converted to json The format string is through HttpMessageConverter Methods in realize the transformation of classes . If it is an input parameter, it is bean object , Will call the object getXXX() Method to obtain the property value and encapsulate it in the form of key value pairs , And into json character string . If the input parameter is map aggregate , Will use get(key) How to get value value , And then encapsulate it , And then encapsulate it on the formal parameter .
That's all @ResponseBody Summary of relevant knowledge of annotation , Continue to work hard , come on. ~~~
边栏推荐
- The application could not be installed: INSTALL_ FAILED_ USER_ RESTRICTED
- Huawei cloud from entry to actual combat | cloud rapid site establishment service and enterprise host security service
- Wechat applet application development (I)
- RGB and SATA function switching module based on Quanzhi rk3568j
- [golang from introduction to practice] poker licensing game
- Shell string
- Has baozi ever played in the multi merchant system?
- Swagger simple quick start tutorial
- Chapter 3 business function development (modify the remarks of market activities)
- Only list the data of the specified field GetData ($table, '*', $where, $order)
猜你喜欢

Math. Random, switch selection structure

Day008 select structure (switch statement)

Openharmony Mengxin contribution Guide

Has baozi ever played in the multi merchant system?

Eve-ng lab simulator Cisco, H3C test host alias

Cluster clock synchronization configuration
![Function and technical principle of data desensitization [detailed explanation]](/img/bb/5890d8fd140982ea7b994942093cc7.png)
Function and technical principle of data desensitization [detailed explanation]

Analytic hierarchy process of MATLAB

C language: string processing function

After the failure of listing in Hong Kong, tuba rabbit terminated its gem IPO, and the founder responded
随机推荐
Cluster clock synchronization configuration
Behind Senma's LP, "Wenzhou Department" is running into the venture capital circle
Which securities company is better to open an account? Is it safe to open an account on your mobile phone
Hbuilderx eslint configuration
The United States has launched 337 investigations on a number of Chinese companies: Bubugao is full of lying guns!
Millet 100W fast charging, 50W wireless charging technology exposure! Oppo Shen Yiren responded: boring!
Win11 experience
暗黑王者|ZEGO 低照度图像增强技术解析
Bond network card mode setting
Geely and Daimler set up a joint venture to produce pure electric smart in China!
[internship] processing time
如何取得数据库创建时间?
Maker concept design to adapt to popular education
[cloud picture theory] 247 first introduction to Huawei cloud analysis service
Do you really understand images? (machine vision)
What is behind the development of science and technology now is the advent of the era of the meta universe
Properties of trees
[golang from introduction to practice] poker licensing game
Function and technical principle of data desensitization [detailed explanation]
Kubesphere 3.3.0 offline installation tutorial