当前位置:网站首页>@ResponseBody的作用
@ResponseBody的作用
2022-06-30 14:10:00 【全栈程序员站长】
作用:
该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区。
使用时机:
返回的数据不是html标签的页面,而是其他某种格式的数据时(如json、xml等)使用;
如,返回的是一个page分页对象
@ResponseBody
@RequestMapping("/localIdentifyCheckList")
public Page<TmCreditHistory> localIdentifyCheckList(String appNo){
Page<TmCreditHistory> page = new Page<TmCreditHistory>();
List<TmCreditHistory> tmCreditHistoryList = new ArrayList<TmCreditHistory>();
try {
tmCreditHistoryList = commonService.checkIdentifyForLocal(appNo);
} catch (ProcessException e) {
logger.error(LogPrintUtils.printAppNoLog(appNo, null)+"获取核身信息失败!["+e.getMessage()+"]");
}
for (TmCreditHistory tmCreditHistory : tmCreditHistoryList) {
page.getRows().add(tmCreditHistory);
}
return page;
}
如:返回的是json串
@ResponseBody
@RequestMapping("/netWorkNciic")
public Json netWorkNciic(String appNo){
Json json = Json.newSuccess();
IdentifyCheckResp resp = null;
try {
resp = commonService.checkIdentifyForNetWork(appNo);
if (resp == null) {
IdentifyCheckResp identifyCheckResp = new IdentifyCheckResp();
identifyCheckResp.setRspMsg("联机身份核身失败!系统未返回核身结果!");
json.setS(true);
json.setObj(identifyCheckResp);
} else {
Date newDate = DateUtils.stringToDate(resp.getEntrustDate(),DateUtils.FULL_THRID_LINE);
resp.setEntrustDate(DateUtils.dateToString(newDate, DateUtils.FULL_SECOND_LINE));
json.setS(true);
json.setObj(resp);
}
} catch (ParseException e) {
logger.error("日期格式转换错误!"+e.getMessage());
} catch (Exception e) {
IdentifyCheckResp resp1 = new IdentifyCheckResp();
resp1.setRspMsg("联机身份核身失败!["+e.getMessage()+"]");
resp1.setEntrustDate("");
json.setS(true);
json.setObj(resp1);
logger.error(LogPrintUtils.printAppNoLog(appNo, null)+"联机失败!["+e.getMessage()+"]");
}
return json;
}
如这种返回一个页面的就不需要:
@RequestMapping("/whichQueryMethod")
public String whichQueryMethod(String localOrCis,String appNo){
setAttr("localOrCis", localOrCis);
setAttr("appNo", appNo);
return "apply/common/cis5OrgProductBut_V1.ftl";
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106258.html原文链接:https://javaforall.cn
边栏推荐
- There is no utf8 option for creating tables in Navicat database.
- Mysql database foundation: stored procedures and functions
- 幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
- 科普达人丨漫画图解什么是eRDMA?
- 智慧运维:基于 BIM 技术的可视化管理系统
- Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
- 数据库表为什么写不进数据了
- Rpm2rpm packaging steps
- Flat shading with unity
- visualstudio 和sql
猜你喜欢
SQL programming problem, test case failed
This editor will open source soon!
[kali] Kali system, software update (with image source)
How to execute a query SQL
Google Earth Engine(GEE)——将字符串的转化为数字并且应用于时间搜索( ee.Date.fromYMD)
Assertions of regular series
“即服务”,企业数字化转型的必然选择
Step by step | help you easily submit Google play data security form
How can I protect my private key?
Unity animator parameter
随机推荐
Assertions of regular series
[Title brushing] heater
Dart 扩展特性
Calculates the length of the last word in a string, separated by spaces
MySQL access denied, opened as Administrator
Rpm2rpm packaging steps
This editor will open source soon!
(8)JMeter元件详解之 Once only Controller 仅一次控制器
LeetCode_ Stack_ Medium_ 227. basic calculator II (without brackets)
QQ was stolen? The reason is
Getting started with shell Basics
How to execute a query SQL
Golang template (text/template)
What is erdma as illustrated by Coptic cartoon?
When SQL queries are performed in table storage, an error is reported when the primary key is added to the query result, and the query result exceeds 10W rows. Do you want to add multiple indexes to t
Knowledge dissemination cannot replace professional learning!
numpy 创建空数组 data = np.empty(shape=[1, 64,64,3])
目录相关命令
Pit used by go language array type
(8) JMeter component detailed once only controller