MyBatis: How to return custom map -


here table:

create table `constant` (   `type` varchar(45) not null,   `param` varchar(45) not null,   `value` varchar(255) not null default '',   primary key (`type`,`param`) ) engine=innodb default charset=utf8; 

i want param map key , value map value, little confused getting simple way.

my code:

@select("select param, value constant type = #{type}") @mapkey("param") map<string, string> getconstantbytype(@param("type") string type); 

you have create result handler work.

when calling method pass result handler

resulthandler class:

public class someresulthandler implements resulthandler<object> {   private map<string, string> map = new hashmap<string, string>();  @override public void handleresult(resultcontext<?> resultcontext) {     try {         @suppresswarnings("unchecked")         map<string, object> result = (map<string, string>) resultcontext.getresultobject();                              map.put(result.get("param").tostring(), result.get("value").tostring());     } catch (exception exception) {         // exception handler     }  }  public map<string, string> getmap() {     return map; } } 

pass resulthandler method call. used java stack.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -