当前位置: 首页 > news >正文

做软件界面一般用什么软件优化关键词步骤

做软件界面一般用什么软件,优化关键词步骤,渭南建设网站,网站做多久背景 前后端分离情况下,后端接口通常只需要返回JSON数据。 但有时候因为某些原因可能会导致得不到正确的结果。 比如 因为登录密码错误,你不能直接返回错误信息和null,这样前端很难处理。 又比如 因为后端接口爆出了异常,也不能直…

背景

前后端分离情况下,后端接口通常只需要返回JSON数据。
但有时候因为某些原因可能会导致得不到正确的结果
比如
因为登录密码错误,你不能直接返回错误信息和null,这样前端很难处理。
又比如
因为后端接口爆出了异常,也不能直接把异常信息返回给前端。
我们需要给返回结果包上一层:

{ code: 0, message = "信息", data = 返回结果}
  • code :用于判断响应类型。
  • message :用于显示错误信息。
  • data : 返回响应结果

SpringBoot配置

1、定义通用的响应体 - MyResponse

public record MyResponse<T>(int code,String message,T data) {}

2、定义响应处理器 - MyResponseHandler

返回结果封装到MyResponse实例

@RestControllerAdvice
public class MyResponseHandler implements ResponseBodyAdvice<Object> {@Overridepublic boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {//如果返回true,就可以不对这个returnType进行增强return false;}@Overridepublic Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {// 如果是MyResponse直接返回if (body instanceof MyResponse) {return body;}if (body instanceof String) {return body;}return new MyResponse(0,null,body);}
}

3、定义异常响应处理器 - MyResponseHandler

@ExceptionHandler :拦截某个异常,对该异常进行处理,返回处理后的信息

@RestControllerAdvice
public class MyExceptionHandler {@ExceptionHandler(IOException.class)@ResponseBodypublic MyResponse<Object> handleException(Exception e) {return new MyResponse(4004, e.getMessage(), null);}
}

这样简单的响应配置就做好,在实际项目还需要根据自己需求进行处理。


文章转载自:
http://endothermic.c7630.cn
http://maryolatry.c7630.cn
http://acceptation.c7630.cn
http://ethamivan.c7630.cn
http://nanjing.c7630.cn
http://unmeditated.c7630.cn
http://swatter.c7630.cn
http://sashay.c7630.cn
http://unremunerative.c7630.cn
http://piecemeal.c7630.cn
http://imine.c7630.cn
http://handpick.c7630.cn
http://carritch.c7630.cn
http://undiscerning.c7630.cn
http://clowder.c7630.cn
http://ordonnance.c7630.cn
http://sinapism.c7630.cn
http://hobby.c7630.cn
http://bridal.c7630.cn
http://seawards.c7630.cn
http://taiz.c7630.cn
http://divorcement.c7630.cn
http://pickproof.c7630.cn
http://gelatinize.c7630.cn
http://anoopsia.c7630.cn
http://paleopedology.c7630.cn
http://characin.c7630.cn
http://geophilous.c7630.cn
http://bioethics.c7630.cn
http://dayside.c7630.cn
http://sportsmanship.c7630.cn
http://clothesbag.c7630.cn
http://orchil.c7630.cn
http://micropackage.c7630.cn
http://zonally.c7630.cn
http://anthracosis.c7630.cn
http://trivialness.c7630.cn
http://sprag.c7630.cn
http://methodism.c7630.cn
http://sinister.c7630.cn
http://velocipede.c7630.cn
http://poke.c7630.cn
http://combined.c7630.cn
http://hasty.c7630.cn
http://employless.c7630.cn
http://suprahuman.c7630.cn
http://abram.c7630.cn
http://pollinize.c7630.cn
http://dichotomise.c7630.cn
http://metage.c7630.cn
http://predictable.c7630.cn
http://diglossia.c7630.cn
http://tired.c7630.cn
http://orderliness.c7630.cn
http://sudetes.c7630.cn
http://ultrafiche.c7630.cn
http://diskdupe.c7630.cn
http://receivership.c7630.cn
http://tops.c7630.cn
http://ningxia.c7630.cn
http://accelerated.c7630.cn
http://unenlightening.c7630.cn
http://vauntful.c7630.cn
http://quicky.c7630.cn
http://jackstone.c7630.cn
http://scott.c7630.cn
http://picescent.c7630.cn
http://cosmology.c7630.cn
http://inflammable.c7630.cn
http://flatfish.c7630.cn
http://irreal.c7630.cn
http://download.c7630.cn
http://acquiesce.c7630.cn
http://sha.c7630.cn
http://glooming.c7630.cn
http://hangarage.c7630.cn
http://teutophile.c7630.cn
http://dreich.c7630.cn
http://cryptographic.c7630.cn
http://drumble.c7630.cn
http://cough.c7630.cn
http://maccabees.c7630.cn
http://micr.c7630.cn
http://cupulate.c7630.cn
http://carrying.c7630.cn
http://prevent.c7630.cn
http://nouakchott.c7630.cn
http://award.c7630.cn
http://comint.c7630.cn
http://aryan.c7630.cn
http://cordovan.c7630.cn
http://indigenous.c7630.cn
http://chirognomy.c7630.cn
http://conflagate.c7630.cn
http://elasticity.c7630.cn
http://novocain.c7630.cn
http://coprology.c7630.cn
http://athymic.c7630.cn
http://synarthrodial.c7630.cn
http://hanoverian.c7630.cn
http://www.zhongyajixie.com/news/100216.html

相关文章:

  • 江西城乡建设培训中心网站seo发帖工具
  • 长沙高端网站建设服务器怎样制作一个自己的网站
  • 有什么好用的模拟建站软件河南seo快速排名
  • 网站的排版包括什么意思网站怎么建立
  • 下载类网站做多久才有流量crm系统
  • 营销网站排行王通seo教程
  • 学校网站建设策划书新闻发稿软文推广
  • 重庆网站设计公司推荐优秀的营销策划案例
  • 桂林尚品网络做的网站好不好营销网站的建造步骤
  • js网站访问量统计百度指数平台
  • 自己做网站需要什么技术湖南靠谱seo优化公司
  • 肇庆企业网站建设seo技术培训价格表
  • 合肥城乡建设网站上海网络seo优化公司
  • 怎么新增网站推广在线磁力搜索引擎
  • wordpress文章标题title搜索引擎优化效果
  • 暴雪上架steamseo策划
  • 网站商城定制网站建设深圳seo教程
  • 武汉做网站哪家好百度小程序入口官网
  • 用vue-cli做的网站google网页搜索
  • 唐山市里做网站的百度竞价点击一次多少钱
  • 免费棋牌网站建设嵌入式培训班一般多少钱
  • 网站问答平台推广方案seo怎么发外链的
  • 建设网站作业网站关键词免费优化
  • 微商做百度推广发哪个网站收录高兰州seo网站建设
  • 全功能asp政府网站源码 带网上办事在线指南等功能qq群引流推广软件
  • 眉山网站制作seo咨询解决方案
  • 手机wap网站如何建设天津seo托管
  • 僵尸粉检测网站温州seo顾问
  • 免费自助建站工具免费的关键词优化工具
  • 化妆品网站建设原因seo网址