栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

groovy

groovy

groovy

groovy学习资料:

The Apache Groovy programming language - documentation

GStringTemplateEngine (Groovy 4.0.0)

模版中map的处理可参考:

groovy-map.each{}_weixin_30687051的博客-CSDN博客

模版中list的处理可参考:

https://blog.csdn.net/coderinchina/article/details/92081323

依赖:


    org.springframework.boot
    spring-boot-starter-groovy-templates


    org.codehaus.groovy
    groovy


    org.codehaus.groovy
    groovy-ant


    org.codehaus.groovy
    groovy-json


    org.apache.maven.plugins
    maven-compiler-plugin
    3.1
    
        groovy-eclipse-compiler
        ${java.version}
        ${java.version}
    

    
        
            org.codehaus.groovy
            groovy-eclipse-compiler
            2.9.1-01
        

        
            org.codehaus.groovy
            groovy-eclipse-batch
            2.3.7-01
        

    


    org.codehaus.groovy
    groovy-eclipse-compiler
    2.9.1-01
    true

创建目录:

File dir=File.createTempFile('tmp', '', new File(“路径”))

dir.mkdirs()

在父目录下创建目录:

File childDir= new File(rootDir, “子目录名称”)
childDir.mkdirs()

在目录下创建文件并写入内容【写入一个xml文件,这边使用groovy进行字符串替换模版占位符】:

String yhXml=“ceshi/pom.xml”

Map model;//model中可以存储模版中对应的内容

groovy进行字符串替换模版占位符:

//处理模版源文件

//获取模版

GStringTemplateEngine  templateEngine=new GStringTemplateEngine()

Template template

def classLoader = GroovyTemplate.class.classLoader

def resource = classLoader.getResource(name)
if (resource) {
   template =engine.createTemplate(resource)
}

template =engine.createTemplate(name)

//字符串替换模版占位符

Writable writable=template.make(model)

def result = new StringWriter()
writable.writeTo(result)

String pom = new String(result.toString())

//在目录下将pom内容写入创建文件中

new File(childDir, 'pom.xml').write(pom)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/730673.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号