中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

免費網(wǎng)站建設(shè)作業(yè)總結(jié)seo的作用主要有

免費網(wǎng)站建設(shè)作業(yè)總結(jié),seo的作用主要有,公司微信小程序定制,北京工廠網(wǎng)站建設(shè)前言 在前后端開發(fā)中,后端接口返回的數(shù)據(jù)都是JSON格式的,但是后端可能會出現(xiàn)一些可以未知從異常,在后端拋出這些異常的時候,也需要返回相同格式的JSON數(shù)據(jù),這時候就需要我們設(shè)置全局異常處理器。在后端開發(fā)中&#xf…

前言

在前后端開發(fā)中,后端接口返回的數(shù)據(jù)都是JSON格式的,但是后端可能會出現(xiàn)一些可以未知從異常,在后端拋出這些異常的時候,也需要返回相同格式的JSON數(shù)據(jù),這時候就需要我們設(shè)置全局異常處理器。在后端開發(fā)中,需要對一些條件做判斷,也可以拋出自定義的異常。話不多說,直接上代碼

代碼

  1. 自定義異常
/*** 業(yè)務(wù)異常*/
public final class ServiceException extends RuntimeException {private static final long serialVersionUID = 1L;/*** 錯誤碼*/private Integer code;/*** 錯誤提示*/private String message;/*** 錯誤明細(xì),內(nèi)部調(diào)試錯誤* <p>* 和 {CommonResult # getDetailMessage()} 一致的設(shè)計*/private String detailMessage;/*** 空構(gòu)造方法,避免反序列化問題*/public ServiceException() {}public ServiceException(String message) {this.message = message;}public ServiceException(String message, Integer code) {this.message = message;this.code = code;}public String getDetailMessage() {return detailMessage;}@Overridepublic String getMessage() {return message;}public Integer getCode() {return code;}public ServiceException setMessage(String message) {this.message = message;return this;}public ServiceException setDetailMessage(String detailMessage) {this.detailMessage = detailMessage;return this;}
}
  1. 定義全局異常處理
import com.juxin.insureclient.common.domain.AjaxResult;
import com.juxin.insureclient.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;import javax.servlet.http.HttpServletRequest;/*** 全局異常處理器*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {/*** 請求方式不支持*/@ExceptionHandler(HttpRequestMethodNotSupportedException.class)public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,HttpServletRequest request){String requestURI = request.getRequestURI();log.error("請求地址'{}',不支持'{}'請求", requestURI, e.getMethod());return AjaxResult.error(e.getMessage());}/*** 業(yè)務(wù)異常*/@ExceptionHandler(ServiceException.class)public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request){log.error(e.getMessage(), e);Integer code = e.getCode();return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());}/*** 攔截未知的運行時異常*/@ExceptionHandler(RuntimeException.class)public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("請求地址'{}',發(fā)生未知異常.", requestURI, e);return AjaxResult.error(e.getMessage());}/*** 系統(tǒng)異常*/@ExceptionHandler(Exception.class)public AjaxResult handleException(Exception e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("請求地址'{}',發(fā)生系統(tǒng)異常.", requestURI, e);return AjaxResult.error(e.getMessage());}
}

3.返回消息格式

import com.juxin.insureclient.common.constant.HttpStatus;
import com.juxin.insureclient.common.utils.StringUtils;import java.util.HashMap;/*** 操作消息提醒*/
public class AjaxResult extends HashMap<String, Object> {private static final long serialVersionUID = 1L;/*** 狀態(tài)碼*/public static final String CODE_TAG = "code";/*** 返回內(nèi)容*/public static final String MSG_TAG = "msg";/*** 數(shù)據(jù)對象*/public static final String DATA_TAG = "data";/*** 初始化一個新創(chuàng)建的 AjaxResult 對象,使其表示一個空消息。*/public AjaxResult() {}/*** 初始化一個新創(chuàng)建的 AjaxResult 對象** @param code 狀態(tài)碼* @param msg  返回內(nèi)容*/public AjaxResult(int code, String msg) {super.put(CODE_TAG, code);super.put(MSG_TAG, msg);}/*** 初始化一個新創(chuàng)建的 AjaxResult 對象** @param code 狀態(tài)碼* @param msg  返回內(nèi)容* @param data 數(shù)據(jù)對象*/public AjaxResult(int code, String msg, Object data) {super.put(CODE_TAG, code);super.put(MSG_TAG, msg);if (StringUtils.isNotNull(data)) {super.put(DATA_TAG, data);}}/*** 返回成功消息** @return 成功消息*/public static AjaxResult success() {return AjaxResult.success("操作成功");}/*** 返回成功數(shù)據(jù)** @return 成功消息*/public static AjaxResult success(Object data) {return AjaxResult.success("操作成功", data);}/*** 返回成功消息** @param msg 返回內(nèi)容* @return 成功消息*/public static AjaxResult success(String msg) {return AjaxResult.success(msg, null);}/*** 返回成功消息** @param msg  返回內(nèi)容* @param data 數(shù)據(jù)對象* @return 成功消息*/public static AjaxResult success(String msg, Object data) {return new AjaxResult(HttpStatus.SUCCESS, msg, data);}/*** 返回警告消息** @param msg 返回內(nèi)容* @return 警告消息*/public static AjaxResult warn(String msg) {return AjaxResult.warn(msg, null);}/*** 返回警告消息** @param msg  返回內(nèi)容* @param data 數(shù)據(jù)對象* @return 警告消息*/public static AjaxResult warn(String msg, Object data) {return new AjaxResult(HttpStatus.WARN, msg, data);}/*** 返回錯誤消息** @return*/public static AjaxResult error() {return AjaxResult.error("操作失敗");}/*** 返回錯誤消息** @param msg 返回內(nèi)容* @return 警告消息*/public static AjaxResult error(String msg) {return AjaxResult.error(msg, null);}/*** 返回錯誤消息** @param msg  返回內(nèi)容* @param data 數(shù)據(jù)對象* @return 警告消息*/public static AjaxResult error(String msg, Object data) {return new AjaxResult(HttpStatus.ERROR, msg, data);}/*** 返回錯誤消息** @param code 狀態(tài)碼* @param msg  返回內(nèi)容* @return 警告消息*/public static AjaxResult error(int code, String msg) {return new AjaxResult(code, msg, null);}/*** 鏈?zhǔn)秸{(diào)用** @param key   鍵* @param value 內(nèi)容* @return 警告消息*/@Overridepublic AjaxResult put(String key, Object value) {super.put(key, value);return this;}
}
http://www.risenshineclean.com/news/42802.html

相關(guān)文章:

  • 做電子商務(wù)系統(tǒng)網(wǎng)站建設(shè)seo的搜索排名影響因素有哪些
  • 手機網(wǎng)站Com臺州做優(yōu)化
  • .net 網(wǎng)站開發(fā)視頻教程系統(tǒng)優(yōu)化軟件有哪些
  • 做外貿(mào)找產(chǎn)品上哪個網(wǎng)站好引流用什么話術(shù)更吸引人
  • t恤定制網(wǎng)站哪個好濟南seo網(wǎng)站優(yōu)化公司
  • 做藥公司的網(wǎng)站前置審批程序員培訓(xùn)機構(gòu)排名
  • 杭州做網(wǎng)站hzfwwl寧波seo網(wǎng)絡(luò)推廣代理公司
  • 用網(wǎng)站做淘寶客的人多嗎有哪些搜索引擎網(wǎng)站
  • 花園休閑平臺設(shè)計百度seo關(guān)鍵詞排名查詢工具
  • 建網(wǎng)站做站在網(wǎng)絡(luò)營銷的現(xiàn)狀和發(fā)展趨勢
  • 茂名網(wǎng)站建設(shè)托管專業(yè)競價托管哪家好
  • 網(wǎng)站建設(shè)總結(jié)報告營銷策劃公司經(jīng)營范圍
  • 太原做網(wǎng)站聯(lián)系方式近三天新聞50字左右
  • 青島建設(shè)監(jiān)理協(xié)會網(wǎng)站百度seo優(yōu)化教程免費
  • 網(wǎng)站開發(fā) 項目的招標(biāo)文件百度廣告平臺電話
  • 網(wǎng)站建設(shè)福州產(chǎn)品網(wǎng)絡(luò)推廣的方法
  • 如何做網(wǎng)站描述電商入門基礎(chǔ)知識
  • 網(wǎng)站技術(shù)建設(shè)方案百度人氣榜排名
  • python做網(wǎng)站缺點品牌推廣策劃方案
  • 建設(shè)電子商務(wù)網(wǎng)站的必要性線上平臺推廣方案
  • 公司做網(wǎng)站的開支會計分錄怎么做數(shù)據(jù)分析師證書
  • 做標(biāo)簽網(wǎng)站是什么百度賬號注冊
  • 建設(shè)數(shù)字官方網(wǎng)站網(wǎng)絡(luò)推廣員為什么做不長
  • 網(wǎng)站代理備案網(wǎng)絡(luò)運營與推廣
  • 網(wǎng)站開發(fā)中遇到的技術(shù)問題備案域名
  • 周末游做的好的網(wǎng)站點擊器
  • 編寫html的軟件有哪些網(wǎng)站優(yōu)化培訓(xùn)班
  • 機關(guān)網(wǎng)站內(nèi)容建設(shè)查關(guān)鍵詞排名工具app
  • 外國服務(wù)器的網(wǎng)站搜索引擎排名的三大指標(biāo)
  • 手機網(wǎng)站設(shè)計尺寸大小福州關(guān)鍵詞快速排名