当前位置:网站首页>@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. ~~~
边栏推荐
- What tools are available to connect and manage polardb for PostgreSQL databases?
- Which securities company is better to open an account? Is it safe to open an account on your mobile phone
- Do you really understand images? (machine vision)
- [interview must brush 101] greedy algorithm, simulation, string
- Custom dialog (including header and footer)
- Swagger simple quick start tutorial
- Huawei | mlgoperf: ML boot inline for optimizing performance
- DNS domain name resolution
- GBase JDBC 连接数据库异常
- The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market
猜你喜欢

EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs

Visual studio 2019 installation and uninstallation problems

Creativity: Modern Art anonymous oil painting AI works presentation

Wechat applet application development (I)

Simple understanding of RPC

Permanently solve Matplotlib Chinese garbled code

Detailed explanation of kubernetes network plug-in - flannel chapter

Tiktok live broadcast brings goods to help the industry go to sea, and Fastdata observation industry boutique salon helps the ecological development

暗黑王者|ZEGO 低照度图像增强技术解析

Huawei cloud from entry to actual combat | cloud rapid site establishment service and enterprise host security service
随机推荐
GDT,LDT,GDTR,LDTR
Permanently solve Matplotlib Chinese garbled code
Construction of data center (I): background of the emergence of data center
Xrrunner, a domestic performance testing tool for palm smart, officially unveiled qecon
Advanced numbers | [calculus of multivariate function] chain derivation method, implicit function derivation method, total differential form invariance, multivariate function extremum
Student thinking vs workplace thinking
Debezium series: optimize cluster parameters and support personalized settings of debezium connector
Network engineering case: integrated network design of CII company
What are the models of asemi from the manufacturer of rectifier bridge and how about the electroplating process of the manufacturer of rectifier bridge?
ADS1256 debugging notes based on stm32hal Library
暗黑王者|ZEGO 低照度图像增强技术解析
01 create project warehouse
Preparation for Android development in big companies
EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs
Chapter 3 business function development (modify the remarks of market activities)
LVGL 8.2 Tabview
LVGL 8.2 Spinbox
有个问题想请教下,我想用来同步数据库,但我看他是根据mysql 的binlog同步的,如果是大表,一
Localization distillation for dense object detection cvpr2022
JS absolute minimum value of the sum of Huawei od two numbers