由于为了方便工作和若依本身结构明细优秀,本人弄了一个小工具,模板拿的是系统自动生成的部门代码,在其基础之上加以修改的代码

import os
# 该工具用来自动生成RuoYi的页面,
# 使用方法是确保输入地址为预设的模板,
# 输出地址便是所设置的地址,
# 将其覆盖原有的文件夹便可以实现功能。
inpath = "RuoYi_template"
outpath = "RuoYi"
# 模板替换的类型名称,
# obj为小写部分
# Obj 为大写部分
obj = "worker"
Obj = "Worker"
l = len(inpath)
for root, dirs, files in os.walk(inpath, topdown = False):
    # print(dirs)
    # print(files)
    # print(root[l:])
    outdir = root[l:].replace("{object}", obj)
    outdir = outdir.replace("{Object}", Obj)
    if os.path.exists(outpath + "\\" + outdir) == False:
        os.makedirs(outpath + "\\" + outdir)
    for f in files:
        fp = open(root + "\\" + f, "r", encoding = "utf-8")
        f = f.replace("{object}", obj)
        f = f.replace("{Object}", Obj)
        if len(root[l:]) == 0:
            fpout = open(outpath + "\\" + f, "w+", encoding = "utf-8")
        else:
            fpout = open(outpath + outdir + "\\" + f, "w", encoding = "utf-8")
        text = fp.read()
        text = text.replace("{object}", obj)
        text = text.replace("{Object}", Obj)
        fpout.write(text)
        fpout.close()
        fp.close()

 

Logo

快速构建 Web 应用程序

更多推荐