admin
2021-10-12 664cc2fd39177fd3daa6d3988396c704d130882c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.yeshi.utils.generater.vo;
 
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.generater.entity.BaseData;
import org.yeshi.utils.generater.entity.ClassInfo;
 
import javax.annotation.Nullable;
 
/**
 * @author Administrator
 * @title: ExceptionVO
 * @description: 自定义异常输出
 * @date 2021/10/12 10:30
 */
public class ExceptionVO extends BaseData {
 
    private ClassInfo base;
 
    public static class Builder {
        private ClassInfo base;
        private Class entity;
        private String packageName;
 
 
        public Builder setBase(@Nullable ClassInfo base) {
            this.base = base;
            return this;
        }
 
        public Builder setEntity(Class entity) {
            this.entity = entity;
            return this;
        }
 
        public Builder setPackageName(String packageName) {
            this.packageName = packageName;
            return this;
        }
 
        public ExceptionVO build() throws Exception {
            if (entity == null) {
                throw new Exception("entity不能为空");
            }
 
            if (this.base == null) {
                this.base = new ClassInfo(Exception.class.getSimpleName(), Exception.class.getName());
            }
 
            if (StringUtil.isNullOrEmpty(packageName)) {
                throw new Exception("packageName不能为空");
            }
 
            ExceptionVO vo = new ExceptionVO();
            vo.setBase(base);
            vo.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName()));
            vo.setPackageName(packageName);
            return vo;
        }
    }
 
 
    public ClassInfo getBase() {
        return base;
    }
 
    public void setBase(ClassInfo base) {
        this.base = base;
    }
}