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
Post a Comment