I am using IBatis for Java (ibatis2-2.3.4) I have a procedure which I am calling which takes 1 IN
param and 4 OUT
params. I have configured this in my IBatis
mapping file as such:
<procedure id="GENERATE_FILES" parameterMap="GENERATE_FILES_MAP">
{ call PAUL.GENERATE_FILES ( ?, ?, ?, ?, ? ) }
</procedure>
I would like to use the 4 OUT params to create my target object in my mapping file. Instead based on the configuration below the OUT objects just get set in the Map and I need 开发者_StackOverflow中文版to create the target object in my Java code.
<parameterMap id="GENERATE_FILES_MAP" class="java.util.Map">
<parameter property="ID" jdbcType="NUMERIC" javaType="java.lang.Long" mode="IN" />
<parameter property="CODE" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT" />
<parameter property="NAME" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT" />
<parameter property="CREATE_DT" jdbcType="DATE" javaType="java.util.Date" mode="OUT"/>
<parameter property="LINK_DT" jdbcType="DATE" javaType="java.util.Date" mode="OUT"/>
</parameterMap>
So - anybody any ideas how I could use these 4 OUT
params to create my target object within the mapping file?
Thanks, Paul.
Instead of using a java.util.Map as the class passed to the parameters Map you can use a JavaBean with the five properties you need; for example you can have:
public class MyClass {
private long id;
private String code;
private String name;
private Date createDate;
private Date linkDate;
// getters and setters....
}
And then use it in your parameterMap:
<parameterMap id="GENERATE_FILES_MAP" class="MyClass">
<parameter property="id" jdbcType="NUMERIC" mode="IN" />
<parameter property="code" jdbcType="VARCHAR" mode="OUT" />
<parameter property="name" jdbcType="VARCHAR" mode="OUT" />
<parameter property="createDate" jdbcType="DATE" mode="OUT"/>
<parameter property="linkDate" jdbcType="DATE" mode="OUT"/>
</parameterMap>
So, when with you SqlMapClient you will call the procedure using the queryForObject() method you will pass an instance of you JavaBean to it with the id property valorized and will have the other properties valorized by the query.
精彩评论