MyException rename to BlogResponseException

This commit is contained in:
禾几海
2021-10-01 15:48:27 +08:00
parent ef2f98e45f
commit fa120a6da5
17 changed files with 127 additions and 146 deletions

View File

@@ -1,16 +1,19 @@
package cn.celess.common;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
@SpringBootApplication(
scanBasePackageClasses = {
CommonApplication.class
}
)
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
@MapperScan("cn.celess.common.mapper")
public class CommonApplication {
public static void main(String[] args) {
SpringApplication.run(CommonApplication.class, args);

View File

@@ -1,22 +0,0 @@
package cn.celess.common.config;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan("cn.celess.common.mapper")
@Slf4j
public class MybatisConfig {
// @Bean
// public SqlSessionFactory sqlSessionFactory() throws Exception {
// log.info("配置Mybatis的配置项");
// PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
// // 此处省略部分代码
// bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
// bean.setTypeAliasesPackage("cn.celess.common.entity");
// return bean.getObject();
// }
}

View File

@@ -8,32 +8,32 @@ import lombok.Data;
* @date : 2019/03/28 16:56
*/
@Data
public class MyException extends RuntimeException {
public class BlogResponseException extends RuntimeException {
private int code;
private Object result;
public MyException(int code, String msg) {
public BlogResponseException(int code, String msg) {
super(msg);
this.code = code;
}
public MyException(ResponseEnum e) {
public BlogResponseException(ResponseEnum e) {
super(e.getMsg());
this.code = e.getCode();
}
public MyException(ResponseEnum e, Object result) {
public BlogResponseException(ResponseEnum e, Object result) {
super(e.getMsg());
this.code = e.getCode();
this.result = result;
}
public MyException(ResponseEnum e, String msg) {
public BlogResponseException(ResponseEnum e, String msg) {
super(msg + e.getMsg());
this.code = e.getCode();
}
public MyException(ResponseEnum e, String msg, Object result) {
public BlogResponseException(ResponseEnum e, String msg, Object result) {
super(e.getMsg());
this.code = e.getCode();
this.result = result;

View File

@@ -38,8 +38,8 @@ public class ExceptionHandle {
@ResponseBody
public Response handle(Exception e) {
//自定义错误
if (e instanceof MyException) {
MyException exception = (MyException) e;
if (e instanceof BlogResponseException) {
BlogResponseException exception = (BlogResponseException) e;
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
}