NutzCN Logo
问答 nutz有占位符的封装吗
发布于 44天前 作者 Hamming 99 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz有占位符的封装吗 列如 这样 字符串拼接

    public static String getFileName(String template, TableInfo table, String moduleName) {
        // 小写类名
        String classname = table.getClassname();
        // 大写类名
        String className = table.getClassName();
        String javaPath = PROJECT_PATH;
        String javaPathOpen = PROJECT_PATH_OPEN;
        String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + classname;

        if (Lang.isNotEmpty(classname)) {
            javaPath = javaPath.replace(".", "/") + "/";
        }

        if (template.contains("Models.java.vm")) {
            return javaPath + "models" + "/" + className + ".java";
        }

        if (template.contains("Service.java.vm")) {
            return javaPath + "services" + "/" + className + "Service.java";
        }
        if (template.contains("ServiceImpl.java.vm")) {
            return javaPath + "services/impl" + "/" + className + "ServiceImpl.java";
        }
        if (template.contains("ApiController.java.vm")) {
            return javaPathOpen + "/Api" + className + "Controller.java";
        }
        if (template.contains("Controller.java.vm")) {
            return javaPath + "controller" + "/" + className + "Controller.java";
        }
        if (template.contains("list.html.vm")) {
            return htmlPath + "/" + classname + ".html";
        }
        if (template.contains("add.html.vm")) {
            return htmlPath + "/" + "add.html";
        }
        if (template.contains("edit.html.vm")) {
            return htmlPath + "/" + "edit.html";
        }
        if (template.contains("tree.html.vm")) {
            return htmlPath + "/" + "tree.html";
        }
        if (template.contains("sql.vm")) {
            return classname + "Menu.sql";
        }
        return null;
    }

有没有nutz的工具 可以用占位符 传参数进去

    public static String getFileName(String template, GenTable genTable)
    {
        // 文件名称
        String fileName = "";
        // 包路径
        String packageName = genTable.getPackageName();
        // 模块名
        String moduleName = genTable.getModuleName();
        // 大写类名
        String className = genTable.getClassName();
        // 业务名称
        String businessName = genTable.getBusinessName();

        String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
        String mybatisPath = MYBATIS_PATH + "/" + moduleName;
        String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;

        if (template.contains("domain.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/domain/{}.java", javaPath, businessName, className);
        }
        else if (template.contains("mapper.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/mapper/{}Mapper.java", javaPath, businessName, className);
        }
        else if (template.contains("service.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/service/I{}Service.java", javaPath, businessName, className);
        }
        else if (template.contains("serviceImpl.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/service/impl/{}ServiceImpl.java", javaPath, businessName, className);
        }
        else if (template.contains("controller.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/controller/{}Controller.java", javaPath, businessName, className);
        }
        else if (template.contains("mapper.xml.vm"))
        {
            fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
        }
        else if (template.contains("list.html.vm"))
        {
            fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
        }
        else if (template.contains("list-tree.html.vm"))
        {
            fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
        }
        else if (template.contains("tree.html.vm"))
        {
            fileName = StringUtils.format("{}/tree.html", htmlPath);
        }
        else if (template.contains("add.html.vm"))
        {
            fileName = StringUtils.format("{}/add.html", htmlPath);
        }
        else if (template.contains("edit.html.vm"))
        {
            fileName = StringUtils.format("{}/edit.html", htmlPath);
        }
        else if (template.contains("sql.vm"))
        {
            fileName = businessName + "Menu.sql";
        }
        return fileName;
    }
4 回复

试试EL.eval

看不懂 有文档参考吗

试着用设计模式,
busyness 1 个
factory 生成
12 个文件管理类。

        if (template.contains("domain.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/domain/{}.java", javaPath, businessName, className);
        }
        else if (template.contains("mapper.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/mapper/{}Mapper.java", javaPath, businessName, className);
        }
        else if (template.contains("service.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/service/I{}Service.java", javaPath, businessName, className);
        }
        else if (template.contains("serviceImpl.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/service/impl/{}ServiceImpl.java", javaPath, businessName, className);
        }
        else if (template.contains("controller.java.vm"))
        {
            fileName = StringUtils.format("{}/{}/controller/{}Controller.java", javaPath, businessName, className);
        }
        else if (template.contains("mapper.xml.vm"))
        {
            fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
        }
        else if (template.contains("list.html.vm"))
        {
            fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
        }
        else if (template.contains("list-tree.html.vm"))
        {
            fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
        }
        else if (template.contains("tree.html.vm"))
        {
            fileName = StringUtils.format("{}/tree.html", htmlPath);
        }
        else if (template.contains("add.html.vm"))
        {
            fileName = StringUtils.format("{}/add.html", htmlPath);
        }
        else if (template.contains("edit.html.vm"))
        {
            fileName = StringUtils.format("{}/edit.html", htmlPath);
        }
        else if (template.contains("sql.vm"))
        {
            fileName = businessName + "Menu.sql";
        }
 跟据busyness决定是否能生成出每一个文件。

装饰器
7 个装饰器

        // 包路径
        String packageName = genTable.getPackageName();
        // 模块名
        String moduleName = genTable.getModuleName();
        // 大写类名
        String className = genTable.getClassName();
        // 业务名称
        String businessName = genTable.getBusinessName();

        String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
        String mybatisPath = MYBATIS_PATH + "/" + moduleName;
        String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;

每个文件管理类都可以决定自己不使用哪些装饰器

二次循环完成代码。

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