【问题标题】:how to get the data in url using groovy code?如何使用 groovy 代码获取 url 中的数据?
【发布时间】:2016-03-15 05:46:09
【问题描述】:

我想使用 groovy 代码从 url 获取缺陷 ID(在任务顶部构建自定义代码)。

例如:我将生成一个动态网址,例如 www.xyz.com/abc/defect_123/ 现在我想检索始终从第 17 位开始的那个字母。并返回字符串

请帮忙.. 提前致谢

【问题讨论】:

    标签: groovy rtc tasktop


    【解决方案1】:

    这里有两种可能性。请注意,“子字符串”选项非常严格,总是从第 16 位开始(如果域从 www.xyz.com 更改为 www.xyzw.com 会怎样?)

    def str = 'www.xyz.com/abc/defect_123/';
    
    def pieces = str.tokenize('/'); // prints defect_123
    def from16 = str.substring(16); // prints defect_123/
    
    println from16;
    println pieces.last();
    

    【讨论】:

      【解决方案2】:

      您应该在 UrlMappings.groovy 文件中将其定义为动态 url:

      "www.xyz.com/abc/$defect_id" (controller: 'YourController', action: 'method_name')

      您可以使用 params.defect_id

      YourController 访问 defect_id 变量

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-26
        • 1970-01-01
        • 2019-06-21
        • 2014-11-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多