java - Returning a Constant in an iBatis resultMap -


i have resultmap set number of result elements in it. able set constant 1 of results. instead of

<result property="name" column="name"/> 

i'd able make sure name come string 'joe'. in ideal world i'd have query changed return constant unfortunately that's not option me. i've scanned on ibatis dtd , unable find suitable attribute. know iterate on list returned ibatis i'd prefer able in ibatis map. thanks

yesnotypehandler.java compatible mybatis 3 :

abc-sqlmaps.xml

<resultmap id="resultmapabc" class="com.abc.dto.abc">         ...         <result property="isa" column="is_a" typehandler="yesnotypehandler"/>         ... </resultmap> 

ibatis.xml

<sqlmapconfig>     ...     <typealias alias="yesnotypehandler" type="com.abc.dao.sqlmap.yesnotypehandler"/>     <typehandler javatype="boolean" jdbctype="boolchar" callback="yesnotypehandler"/>     ... </sqlmapconfig>     import java.sql.callablestatement; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception;  import org.apache.ibatis.type.jdbctype; import org.apache.ibatis.type.typehandler;  public class yesnotypehandler implements typehandler {      @override     public void setparameter(preparedstatement parampreparedstatement, int paramint, object paramobject, jdbctype paramjdbctype) throws sqlexception {         if (paramobject == null) {             parampreparedstatement.setstring(paramint, "n");         }         else {             boolean value = (boolean) paramobject;              parampreparedstatement.setstring(paramint, value ? "y" : "n");         }     }       @override     public object getresult(resultset getter, string columnlabel) throws sqlexception {         string value = getter.getstring(columnlabel);         if (getter.wasnull()) { return false; }         return "y".equalsignorecase(value);      }      @override     public object getresult(callablestatement cs, int columnnb) throws sqlexception {         string value = cs.getstring(columnnb);         if (cs.wasnull()) { return false; }         boolean boolvalue = "y".equalsignorecase(value);         return boolvalue;     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -