当前位置:网站首页>@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
边栏推荐
- 【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
- 【系统分析师之路】第五章 复盘软件工程(软件过程改进)
- navicat数据库建表是没有utf8选项。
- Dart 扩展特性
- [the path of system analyst] Chapter 5 Software Engineering (Agile Development)
- 服务线上治理
- 第四批入围企业公示——年度TOP100智能网联供应商评选
- golang模板(text/template)
- [Title brushing] coco, who likes bananas
- SQL programming problem, test case failed
猜你喜欢

Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance

正则系列之断言Assertions

Problems in QT creator (additional unknown and error lines are listed in the debug output window)
![[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure](/img/5a/5da6180db0b2b96660bcd9b4fa0633.png)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure

The programming competition is coming! B station surrounding, senior members and other good gifts to you!

visualstudio 和sql

Unity Animator 参数

Intelligent operation and maintenance: visual management system based on BIM Technology
![[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)

Pytorch查看模型参数量和计算量
随机推荐
Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit
Unity animator parameter
Defi "where does the money come from"? A problem that most people don't understand
navicat数据库建表是没有utf8选项。
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
[the path of system analyst] Chapter V software engineering (software process improvement)
Pytorch查看模型参数量和计算量
我如何才能保护我的私钥?
Waving flags and shouting for basic language
Knowledge dissemination cannot replace professional learning!
Three uses of golang underscores
数据库表为什么写不进数据了
Simple understanding of the difference between get request and post submission
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
[KALI] KALI系统、软件更新(附带镜像源)
香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
VisualStudio and SQL
正则系列之断言Assertions
目录相关命令
深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结