小编tim*_*tes的帖子

什么意思?在Java?

我有这样一段代码:

private String getUsername(PersonalAccount account) {
    User usr = (User)account?.usr
    String name = usr?.getName()
    return name
}
Run Code Online (Sandbox Code Playgroud)

在PersonalAccount类中我们有字段:

SimpleUser usr
Run Code Online (Sandbox Code Playgroud)

用户扩展了SimpleUser

这意味着什么:?在这两行?

User usr = (User)account?.usr
    String name = usr?.getName()
Run Code Online (Sandbox Code Playgroud)

groovy

2
推荐指数
1
解决办法
168
查看次数

Grails从config.groovy中访问当前环境

使用Grails OAuth插件需要在Config.groovy中提供绝对回调URL.但是,每个环境都有不同的serverURL.

有没有办法从Config.groovy内部获取当前环境,这是我想要做的一个例子:

def devServerUrl = 'http://dev.example.com'
def prodServerUrl = 'http://prod.example.com'
def currentServerUrl = grailsApplication.metadata.environment == 'development' ? devServerUrl : prodServerUrl;

environments {
    development {
        grails {
            serverURL = devServerUrl
        }
    }
    production {
        grails {
            serverURL = prodServerUrl
        }
    }
}

oauth {
    providers {
        runkeeper {
            api = RunKeeperApi
            key = 'key'
            secret = 'secret'
            callback = currentServerUrl + '/oauth/runkeeper/callback'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

configuration grails

2
推荐指数
1
解决办法
4022
查看次数

命令对象和hasmany

commandObject当我提交表单时,我正在尝试使用它来验证我的数据.我可以在中验证hasMany关系吗commandObject?我的cenario是这样的.

牵引简单的classeswhith有很多关系:

class Book{
    String nameBook
}

class Author{
    String nameAuthor
    static hasMany = [books:Book]    
}
Run Code Online (Sandbox Code Playgroud)

很简单commandObject,我想在提交表单时验证hasMany.

@grails.validation.Validateable
class MyValidateCommand{

    String nameAuthor
    static hasMany = [books:Book]


    static constraints = {
        nameAuthor nullable:false
        books nullable:false
    }

}
Run Code Online (Sandbox Code Playgroud)

ps:我知道这个commandObject是错误的,它不编译.但我可以这样做吗?

grails command-objects

2
推荐指数
1
解决办法
843
查看次数

如何告诉Grails将JSONNull渲染为null?

我有一个从Groovy的HTTPBuilder返回的JSON对象.JSON包含一些表示为JSONNull对象的空值.问题是当我尝试在响应中渲染JSON时,我在尝试渲染JSONNull时出现错误.我得到的回复只是部分呈现的.我希望它呈现为"null".我该怎么做呢?

码:

render(contentType: "text/json") {
    listOfJSONObjectsThatIncludeJSONNulls
}
Run Code Online (Sandbox Code Playgroud)

错误:

| Error 2013-09-17 11:33:56,965 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  - JSONException occurred when processing request: [GET] /my/action
Object is null. Stacktrace follows:
Message: Object is null
   Line | Method
->>  69 | isEmpty        in net.sf.json.JSONNull
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   199 | …
Run Code Online (Sandbox Code Playgroud)

null grails json grails-2.0.4

2
推荐指数
1
解决办法
3061
查看次数

groovy split exception java.lang.ArrayIndexOutOfBoundsException:1

我有这个代码来分割线来获取键值对,如果值丢失则抛出执行.

为什么要施行?拆分此键值对线的正确方法是什么.

def lline="name="
def (key, value) = lline.split("=")
Run Code Online (Sandbox Code Playgroud)

错误:

Caught: java.lang.ArrayIndexOutOfBoundsException: 1
java.lang.ArrayIndexOutOfBoundsException: 1
Run Code Online (Sandbox Code Playgroud)

谢谢

groovy

2
推荐指数
1
解决办法
1724
查看次数

用于将json转换为CSV文件的Groovy代码

有没有人有任何样本Groovy代码将JSON文档转换为CSV文件?我试图在Google上搜索但无济于事.

示例输入(来自评论):

[ company_id: '1',
  web_address: 'vodafone.com/',
  phone: '+44 11111',
  fax: '',
  email: '',
  addresses: [ 
      [ type: "office", 
        street_address: "Vodafone House, The Connection",
        zip_code: "RG14 2FN",
        geo: [ lat: 51.4145, lng: 1.318385 ] ]
  ],
  number_of_employees: 91272,
  naics: [
      primary: [ 
          "517210": "Wireless Telecommunications Carriers (except Satellite)" ],
      secondary: [ 
          "517110": "Wired Telecommunications Carriers",
          "517919": "Internet Service Providers",
          "518210": "Web Hosting"
      ]
  ]
Run Code Online (Sandbox Code Playgroud)

更多来自编辑的信息:

def export(){
   def exportCsv = [ [ id:'1', color:'red', planet:'mars', description:'Mars, the "red" planet'], 
                     [ …
Run Code Online (Sandbox Code Playgroud)

groovy

2
推荐指数
1
解决办法
5740
查看次数

Grails项目运行错误-Server无法启动端口8080:已在使用的地址:JVM_Bind

错误| 服务器无法启动端口8080:地址已在使用中:JVM_Bind(使用--stacktrace查看完整跟踪)

当我第二次使用--- 2 Grails Command(run-app)执行我的grails项目时,每次都会遇到这种类型的错误.

但是当我使用任务管理器杀死javaw.exe时,如果我再次运行它对我有效.这有什么永久的解决方案吗?..请建议.

|包装Grails应用..

|编译10个源文件..

|编译121个源文件.......

|编译9个源文件.........................

|运行Grails应用程序

错误| 服务器无法启动端口8080:地址已在使用中:JVM_Bind(使用--stacktrace查看完整跟踪)

grails

2
推荐指数
1
解决办法
6730
查看次数

不允许在Groovy中使用setter

我开始研究Groovy,对于如何定义类参数我有一些复杂的感觉.默认情况下,它们包括getter和setter,但是如果我不想拥有setter呢?限制为仅允许获取属性值的方法是什么?在C#中可以这样做:

public double Hours
{
    get { return seconds / 3600; }
}
Run Code Online (Sandbox Code Playgroud)

如果我没错的话.

groovy

2
推荐指数
1
解决办法
819
查看次数

+操作符在groovy中的字符串连接中意外地表现

我们习惯于重写toString方法,这样我们就可以通过调用来获取字段值

println"对象详细信息 - > $ object"

我们考虑为我们的构建编写测试用例作为一种良好实践并遵循TDD.

我的测试用例因一些数据缺失而失败.测试用例如下所示:

void "test method:toString"() {
        given:
        CSV csv = new CSV(accountId: '1', accountName: 'testName')

        when:
        String exp = "[accountId=" + csv.accountId + ", groupId)" + csv.groupId + ", accountName=" + csv.accountName +"]"
        String string = csv.toString()

        then:
        string == exp
    }
Run Code Online (Sandbox Code Playgroud)

以下是我的课程:

public class CSV   {
     String accountId
     String groupId
     String accountName
     String chargeMode
     String invoiceId
     String date

    @Override
    public String toString() {
        return "ChargingCsvLine [accountId=" 
               + accountId + ", groupId)" + groupId …
Run Code Online (Sandbox Code Playgroud)

groovy

2
推荐指数
1
解决办法
534
查看次数

如何访问soap UI响应XML的属性值

我对Groovy&Soap UI非常陌生

我有响应XML作为

<carrierUDOResponse ReferenceId="" Result="SUCCESS" xmlns:xsi="" xsi:noNamespaceSchemaLocation="CarrierUDOReponse.xsd
        <errors>
            <error code="0" description="**i WANT TO ACCESS THIS**" property=""/>
        </errors>
        <warnings>
            <warning code="0" description="" property=""/>
        </warnings>
    </errorsAndWarnings>
</carrierUDOResponse>
Run Code Online (Sandbox Code Playgroud)

在Groovy脚本中,我想捕获attribute的值并将其传递到下一步。我应该如何捕捉?

常规脚本如下

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Create_shipment#Response" )
// loop item nodes in response message
for( item in holder.getNodeValues( "//error.code" ))
log.info "errors : [$item]"
def no = holder["count(//error)"]
Run Code Online (Sandbox Code Playgroud)

xml groovy soapui

2
推荐指数
1
解决办法
8887
查看次数