RestApi总结-(二)服务端接口API处理
来源:互联网 发布:安易数据恢复破解版 编辑:程序博客网 时间:2024/06/04 18:59
服务端的ResponseBody和ResponseEntity
随着WEB2.0相关技术的崛起,我们很多时候只需要返回数据即可。
ResponseBody
将内容或对象作为 HTTP 响应正文返回,并调用适合HttpMessageConverter的Adapter转换对象,写入输出流。
ResponseEntity
extends HttpEntity 在ResponseBody的基础上封装了一个网络返回状态。
统一接口标准格式
@RequestMapping("/verification")@ResponseBodypublic ResponseEntity<InvokeResult> getVerification(String cellPhone){ InvokeResult invokeResult; try { if(StringUtils.isEmpty(cellPhone)) { invokeResult = InvokeResult.failure("参数错误!"); } else{ //生成验证码并存入缓存 String verification = msgService.createVerification(cellPhone); logger.info("生成的验证为:" + verification); //发送验证码给cellPhone 上线之前暂不开放 //msgService.sendVerification(verification,cellPhone); invokeResult = InvokeResult.success("短信发送成功,请注意查收!"); } } catch(BizException e){ invokeResult = InvokeResult.failure(e.getMessage()); logger.error(e.getMessage(),e); } catch (Exception e) { logger.error(e.getMessage(),e); invokeResult = InvokeResult.error(); } return new ResponseEntity(invokeResult, HttpStatus.valueOf(invokeResult.getCode()));}public class InvokeResult<T> { private int code; private String msg; private T data;}
阅读全文
0 0
- RestApi总结-(二)服务端接口API处理
- RestApi总结-(一)认识
- 接口加密《二》: API权限设计总结
- 服务端接口交互API设计
- api服务端接口安全性解析
- api服务端接口安全性解析
- 如何写一个RestAPI 接口
- 使用Python访问restAPI接口
- 通过RestClient访问restAPI接口
- 基于restful服务端接口(二)
- Spring MVC 全局异常处理-RESTAPI接口返回统一JSON格式-自定义异常处理--404异常捕捉
- iOS的服务端api接口怎么写
- 服务端 API 接口设计最佳实践
- apicloud数据云api restapi操作
- OCR文字识别HTTP restapi接口设计
- fackbook api 接口 总结
- IP api 接口 总结
- 【API设计风格—RESTful】:服务端如何编写RESTful风格的API(二)
- 数据库字段varchar和Nvarchar区别
- 交换机和路由器的区别有哪些?
- 数据分析学习之roc曲线
- neuq 1096 NEUQ的邮票
- cantos 7 解决libgcc_s.so.1 must be installed for pthread_cancel to work
- RestApi总结-(二)服务端接口API处理
- JS 打印当前页面(或某个DIV内容)
- QSplitter界面布局
- SqlDataAdapter.Update批量数据更新
- IntelliJ IDEA上创建Maven Spring MVC项目
- spring Boot
- 状态机编程
- web开发初步
- Mac ln命令报错:Operation not permitted