How do you map List <string> in iBatis?
I have a class like this
public SomeClass
{
private List<string> _strings = new List<string>();
public IEnumerable<string> Strings
{
{ get return _strings; }
}
}
How do I do a mapping for _strings?
I tried this, but it complains that a List type handler was not found, which it does not complain about if I displayed it as an object.
<result property="_strings" column="value" />
So, I searched Google and found this workaround (initially for a problem with Java, I don’t know if it is supposed to work in C #)
<result property="_strings" resultMapping="someMapping.StringList"/>
<resultMap id="StringList" class="System.String">
<result property="" column="Value"/>
</resultMap>
This, at least, allows me to run the test, and it returns the rest of my object in order, and my list has the correct number of entries, except that they are all empty.
, , , , , , . ( "", ). , , - .
.
- Java- iBATIS, - #.
class MyClass {
int id;
List<String> firstName;
}
( , Integer, String ..) resultMaps
<sqlMap namespace="ns">
<resultMap id="ListMap" class="string">
<result property="firstName" column="firstName"
javaType="java.util.List" jdbcType="VARCHAR"/>
</resultMap>
<resultMap id="PrimaryMap" class="MyClass" groupBy="id">
<result property="id" columnName="id"/>
<result property="firstname" resultMap="ns.ListMap" javaType="java.util.List"/>
</resultMap>
<select id="MySuperQuery" resultMap="PrimaryMap">
select id, firstName from user
</select>
</sqlMap>
, .
Java- IBatis ( 2.3.4). , . Ibatis queryForMap, , , ( : Key - Wrapper, - Wrapper Longs).
( /) .
class PlaceHolder {
private long elementId;;
private List<Long> valueIds;
}
Ibatis
<resultMap id="valueIdsMap" class="java.lang.Long">
<result property="valueIds" column="otherId" javaType="java.util.List" jdbcType="NUMERIC"/>
</resultMap>
<resultMap id="testKeysAndValuesMap" groupBy="elementId" class="PlaceHolder">
<result property="elementId" column="elementId" jdbcType="NUMERIC" javaType="java.lang.Long"/>
<result property="valueIds" resultMap="MapName.valueIdsMap" javaType="java.util.List" />
</resultMap>
<select id="retrieveTestKeysAndValuesMap" resultMap="testKeysAndValuesMap"
parameterClass="java.util.List">
SELECT
table_name_1.column_fk as elementId,
table_name_1.id as otherId
FROM table_name_1
WHERE table_name_1.column_fk IN
<iterate open="(" close=")" conjunction=", ">
#[]#
</iterate>
groupBy . groupBy , elementId, . groupBy , , , , ( , Ibatis, ), resultMap. Ibatis 3, , , .
This worked for me, got a list of lines from the procedure output cursor
List ss = sqlmap.queryList(..
<resultMap id="emailsMap" class="java.lang.String">
<result column="E_MAIL" property="" />
</resultMap>
<parameterMap id="xp" class="java.util.Map">
<parameter property="dd" jdbcType="VARCHAR" mode="IN" />
<parameter property="outPutCursor" javaType="java.sql.ResultSet" jdbcType="ORACLECURSOR" mode="OUT" />
</parameterMap>
enter code here
<procedure id="xx" parameterMap="xp" resultMap="emailsMap">
{ call aaa.bbb(?, ?) }
</procedure>