简体   繁体   中英

How to pass Model as an argument in a method ActiveJDBC

Can I pass Model as an argument in a method using ActiveJDBC?

Something like this:

public Set<String> getColNames(Model modelName){
    Set<String> set = modelName.attributeNames();
    for(String x: set){
       System.out.prtinln(x);
    }
    return set;
}

That way I can just pass the model and would save a lot of time on doing the same code on each Model right? Like this:

Staff staff = new Staff();
Set<String> set = getColNames(staff);

Is this possible??? Getting the attribute names is just an great example on this, this is not only the purpose why I asked this.

Help would be appreciated!

If you could explain why you need this, it would be easier to give directions.

In any case, you can do this with one line of code;

Map values = model.toMap();

See: Model#toMap()

I think that what Igor means, is that you can build your own static method, on a class called Util. This method would be something like this.

public static Set<String > getColNames(Model model) {
    return model.toMap().keySet();
}

Then, you can use it like this:

Staff staff = new Staff();
Set<String> set = Util.getColNames(staff);

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