NutzCN Logo
问答 nutzboot thymeleaf 模板路径获取
发布于 1816天前 作者 Hamming 1684 次浏览 复制 上一个帖子 下一个帖子
标签:

nutzboot thymeleaf 模板路径获取

    /**
     * 生成代码
     */
    public void coding(TableInfo table, List<ColumnInfo> columns, ZipOutputStream zip) {
        // 表名转换成Java属性名
        String className = GenUtils.tableToJava(table.getTableName());
        table.setClassName(className);
        table.setClassname(StringUtils.uncapitalize(className));
        // 列信息
        table.setColumns(GenUtils.transColums(columns));
        // 设置主键
        table.setPrimaryKey(table.getColumnsLast());

        VelocityInitializer.initVelocity();
        String packageName = GenConfig.getPackageName();
        String moduleName = GenUtils.getModuleName(packageName);
        VelocityContext context = GenUtils.getVelocityContext(table);

        // 获取模板列表
        List<String> templates = GenUtils.getTemplates();
        for (String template : templates) {
            // 渲染模板
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, Globals.UTF8);
            tpl.merge(context, sw);
            try {
                // 添加到zip
                zip.putNextEntry(new ZipEntry(GenUtils.getFileName(template, table, moduleName)));
                IOUtils.write(sw.toString(), zip, Globals.UTF8);
                IOUtils.closeQuietly(sw);
                zip.closeEntry();
            } catch (IOException e) {
                throw new BaseException("渲染模板失败,表名:" + table.getTableName(), e.getMessage());
            }
        }
    }

运行 Template tpl = Velocity.getTemplate(template, Globals.UTF8);
变量 路径 templates/vm/java/domain.java.vm
提示找不到路径
文件位于/IdeaProjects/ns/src/main/resources/template/vm/java/domain.java.vm
nutzboot 后端 相对 路径 如何获取呢

2 回复

templates

template

╮(╯▽╰)╭哎 眼瞎
感谢 兽总

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