admin
2022-03-29 fac5d01bfcddfc8edef0a5fd3d401b1fe383fe16
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
package org.yeshi.utils.generater.vo.service;
 
import org.yeshi.utils.generater.entity.BaseData;
import org.yeshi.utils.generater.util.EntityUtil;
import org.yeshi.utils.generater.util.NameUtil;
 
import java.lang.reflect.Field;
 
public class QueryVO extends BaseData {
    private String className;
 
    public static class Builder {
        private Class entity;
        private String packageName;
 
 
        public Builder setEntity(Class entity) {
            this.entity = entity;
            return this;
        }
 
        public Builder setPackageName(String packageName) {
            this.packageName = packageName;
            return this;
        }
 
        private void validParams() throws Exception {
            if (entity == null) {
                throw new Exception("entity不能为空");
            }
            if (packageName == null) {
                throw new Exception("packageName不能为空");
            }
        }
 
 
        public QueryVO build() throws Exception {
            validParams();
            Field identifyId = EntityUtil.getIdentifyId(entity);
            if (identifyId == null) {
                throw new Exception("尚未找到主键属性");
            }
            QueryVO vo = new QueryVO();
            vo.setPackageName(packageName);
            vo.setClassName(NameUtil.getDefaultQueryName(entity));
            return vo;
        }
 
    }
 
    public String getClassName() {
        return className;
    }
 
    public void setClassName(String className) {
        this.className = className;
    }
}