1、引數不滿足條件異常類定義
/**
*@description:引數不滿足異常處理
*@author
*@date: 2023年8月10日 上午14:17:56
*/public class promptexception extends runtimeexception
public void setcode(int code)
public string getmsg()
public void setmsg(string msg)
/*** @param code
* @param msg
*/public promptexception(int code, string msg)
}
2、不滿業務條件異常類定義
/**
*@description:不滿足業務條件異常
*@author
*@date: 2023年8月10日 上午14:17:56
*/public class bu***ception extends runtimeexception
public void setcode(int code)
public string getmsg()
public void setmsg(string msg)
/*** @param code
* @param msg
*/public bu***ception(int code, string msg)
}
3、全域性異常處理類
/**
* @title: gloabexception
* @description:
* @author: liuchuanhong
* @date 2023年9月25日 下午2:56:09
*/@controlleradvice
@responsebody
@slf4j
public class gloabexception else if (e instanceof promptexception) else
} @exceptionhandler()
public string server500(runtimeexception ex)
// 405錯誤
// 400錯誤
@exceptionhandler()
public string requestmissingservletrequest(missingservletrequestparameterexception ex)
// 404錯誤
// valid引數校驗失敗返回
}}
注:需要配置mvc不攔截404等異常
mvc:throw-exception-if-no-handler-found: true
resources:
Springboot專案中Swagger的使用
2.7.0swagger.version properties io.springfoxgroupid springfox swagger uiartifactid version dependency io.springfoxgroupid springfox swagger2artifactid...
SpringBoot專案中Redis配置多資料庫
背景 乙個小需求,單redis服務例項下根據業務配置多個資料庫,需要自定義redis配置稍作改動才能實現,此時就不能redistemplate一步就位了 注 redis使用單執行緒 多路復用 io模型,別把多業務的併發全加在乙個redis例項上,最好多例項或者集群處理!基本的配置我就不多說了,可以參...
Spring Boot 專案中引入 flyway
org.flywaydb flyway core 5.2.4 flyway spring.flyway.baseline on migrate true spring.flyway.baseline description flyway baseline 禁止刪除 schema 下的 table s...