NutzCN Logo
问答 代码生成器问题 空指针
发布于 2579天前 作者 wx_dc1uhcoqb670vfspa24d 1742 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
Connected to the target VM, address: '127.0.0.1:50018', transport: 'socket'
[DEBUG] 15:39:55.289 org.nutz.resource.Scans.printLocations(Scans.java:527) - Locations count=88 time use 104ms
[DEBUG] 15:39:55.304 org.nutz.resource.Scans.scan(Scans.java:280) - Found 1 resource by src( code/code.json ) , regex( ^(.+[.])(js|json)$ )
[DEBUG] 15:39:55.304 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) - loading [code/code.json]
[DEBUG] 15:39:55.324 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:57) - Loaded 3 bean define from path=[code/code.json] --> [conf, dao, dataSource]
[INFO ] 15:39:55.330 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:98) - NutIoc init begin ...
[INFO ] 15:39:55.333 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:121) - ... NutIoc init complete
[DEBUG] 15:39:55.459 cn.wizzer.commons.code.EntityDescLoader.loadTables(EntityDescLoader.java:39) - output dir = /Users/dean/code/GuanfuAPP_OMS2/wk-app/wk-web/target/classes/cn/wizzer/app/gf/modules/models
Disconnected from the target VM, address: '127.0.0.1:50018', transport: 'socket'
Exception in thread "main" java.lang.NullPointerException
	at org.nutz.lang.Mirror.getAnnotation(Mirror.java:592)
	at cn.wizzer.commons.code.EntityDescLoader.loadTables(EntityDescLoader.java:52)
	at cn.wizzer.commons.code.Generator.main(Generator.java:176)

Process finished with exit code 1
@Data
@Table("bbs")
@Comment("论坛")
public class Gf_bbs implements Serializable {
    private static final long serialVersionUID = 1L;

    @Name
    @Column("id")
    @Prev(els = @EL("idGen()"))
    private String id;
    @Column
    @Comment("发布者id")
    private String promulgator_id;
    @Column
    @Comment("发布时间")
    private Long create_time;
    @Column
    @Comment("删除时间")
    private Long delete_time;
    @Column
    @Comment("封面图")
    private String cover;
    @Column
    @Comment("图片集")
    private String imgs;
    @Column
    @Comment("是否发布")
    private boolean publish_status;
    @Column
    @Comment("发布内容")
    private String content;
    @Column
    @Comment("排序")
    @Prev({
            @SQL(db= DB.MYSQL,value = "SELECT IFNULL(MAX(sort),0)+1 FROM bbs")
    })
    private Integer sort;
    @Column
    @Comment("操作者id")
    private String operator;

}

13 回复

这是一个生成getter setter 的插件,class文件中有get set方法

最新的代码吗?

<dependency>
            <groupId>cn.wizzer</groupId>
            <artifactId>wk-code-generator</artifactId>
            <version>4.0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>

cn.wizzer.commons.code.EntityDescLoader.loadTables(EntityDescLoader.java:52)

52行附近的代码贴一下看看, 我对照一下最新的代码, 58行才是 mirror.getAnnotation

public Map<String, TableDescriptor> loadTables(Ioc ioc, String basePackageName, String outputDir, String basePath, String baseUri, String servPackageName, String modPackageName) throws Exception {
        String packageName = modPackageName;
        String filePath = modPackageName.replaceAll("\\.", "\\/");
        URL url = Loader.class.getClassLoader().getResource(filePath);
        String path;
        if (url != null) {
            path = url.getPath();
        } else {
            path = "target/classes/" + filePath;
        }

        File f = Files.createDirIfNoExists(path);
        log.debug("output dir = " + f.getAbsolutePath());
        String abstractPath = URLDecoder.decode(path, "utf8");
        File[] files = Files.lsFile(abstractPath, (String)null);
        Map<String, TableDescriptor> tables = new HashMap();
        File[] var16 = files;
        int var17 = files.length;

        for(int var18 = 0; var18 < var17; ++var18) {
            File file = var16[var18];
            String fileName = file.getName().split("\\.")[0];
            String className = packageName + "." + fileName;
            if (!className.contains(".Model") && !className.contains(".em")) {
                Class<?> modelClass = Class.forName(className);
                Mirror<?> mirror = Mirror.me(modelClass);
                Table tableAnno = (Table)mirror.getAnnotation(Table.class);
                if (tableAnno != null) {
                    String tableName = tableAnno.value();
                    String entityName = modelClass.getSimpleName();
                    TableDescriptor table = new TableDescriptor(tableName, entityName, basePackageName, baseUri, servPackageName, modPackageName);
                    Comment comment = (Comment)mirror.getAnnotation(Comment.class);
                    if (comment != null) {
                        table.setLabel(comment.value());
                    } else {
                        table.setLabel(entityName);
                    }

                    tables.put(tableName, table);
                    tables.put(entityName, table);
                    Field[] fields = mirror.getFields();
                    Field[] var30 = fields;
                    int var31 = fields.length;

                    for(int var32 = 0; var32 < var31; ++var32) {
                        Field field = var30[var32];
                        ColumnDescriptor column = new ColumnDescriptor();
                        String fieldName = field.getName();
                        if (!fieldName.equals("opBy") && !fieldName.equals("opAt") && !fieldName.equals("delFlag")) {
                            column.setFieldName(fieldName);
                            Annotation[] annotations = field.getAnnotations();
                            Annotation[] var37 = annotations;
                            int var38 = annotations.length;

                            for(int var39 = 0; var39 < var38; ++var39) {
                                Annotation annotation = var37[var39];
                                if (annotation instanceof Comment) {
                                    column.setLabel(((Comment)annotation).value());
                                    column.setComment(((Comment)annotation).value());
                                }

                                if (annotation instanceof Id || annotation instanceof Name) {
                                    column.primary = true;
                                    table.setPkType(column.getSimpleJavaTypeName());
                                    column.columnName = fieldName;
                                }

                                if (annotation instanceof ColDefine) {
                                    ColType colType = ((ColDefine)annotation).type();
                                    column.setColumnType(colType.name());
                                    column.dataType = colType.name();
                                }

                                if (annotation instanceof Column) {
                                    String columnName = ((Column)annotation).value();
                                    if (Strings.isBlank(columnName)) {
                                        column.columnName = fieldName;
                                    } else {
                                        column.columnName = columnName;
                                    }
                                }
                            }

                            if (Strings.isEmpty(column.getLabel())) {
                                column.setLabel(fieldName);
                            }

                            table.addColumn(column);
                        }
                    }
                }
            }
        }

        return tables;
    }
}
File f = Files.createDirIfNoExists(path);
        log.debug("output dir = " + f.getAbsolutePath());
        String abstractPath = URLDecoder.decode(path, "utf8");
        File[] files = Files.lsFile(abstractPath, (String)null);
        Map<String, TableDescriptor> tables = new HashMap();
        File[] var16 = files;
        int var17 = files.length;

        for(int var18 = 0; var18 < var17; ++var18) {
            File file = var16[var18];
            String fileName = file.getName().split("\\.")[0];
            String className = packageName + "." + fileName;
            if (!className.contains(".Model") && !className.contains(".em")) {
                Class<?> modelClass = Class.forName(className);
                Mirror<?> mirror = Mirror.me(modelClass);
                Table tableAnno = (Table)mirror.getAnnotation(Table.class);
                if (tableAnno != null) {
               
                Class<?> modelClass = Class.forName(className);
                Mirror<?> mirror = Mirror.me(modelClass);
                Table tableAnno = (Table)mirror.getAnnotation(Table.class);

debug一下, 看看modelClass是不是null,虽然不太可能

cn.wizzer.app.gf.modules.models.Gf_act_info

这是modelClass中name的值 是有值得

贴一下 Gf_act_info

public interface ACTION{

}

Gf_product_order_track$ACTION
我在有一个class中定义了接口
它在获取的时候把接口拼接啦

完整贴一下,我看看能不能重现

@Data
@Table("product_order_track")
public class Gf_product_order_track {

    @Name
    @Prev(els = @EL("idGen()"))
    @Column("id")
    private String id;

    public interface ACTION{
        int BUY_PAY = 1;//买商品(付款)
        int SELL_DAOZHANG=2;//卖商品(到账)
        int PAY_MARGIN = 3;//3.交保证金(付款)
        int BACK_MARGIN = 4; //4.退保证金(退款)
        int DEDUCT = 5; //5.扣除保证金(失效真对买家)
        int DAO_ZHANG =6; //6.保证金到账(失效给卖家)
    }
}

没注意,这里我临时写了个控制状态

添加回复
请先登陆
回到顶部