简体   繁体   中英

bind domain class by unique name

My Grails app has the following command object

class MyCommand {

    @BindUsing({
        obj, source ->
            User.findByUsername(source.username)
    })
    User user

    // other stuff not relevant to this question
}

The request parameters includes a username which uniquely identifies the User . I've added the @BindUsing annotation in order to bind the user property of the command object to the corresponding User instance. However, after databinding has completed, the user field is null, even though the username parameter is correct. What am I doing wrong?

I don't think this has anything to do with retention policy, dynamic finders, withTransaction or withSession. The issue is that the @BindUsing closure is only triggered for the "user" property if there is a request parameter named "user". The description suggests that there probably isn't one in play in this scenario.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM