日期:2014-05-20  浏览次数:20719 次

熟悉Ibatis的进
xmlResultName
当直接把查询结果映射成XML document时,属性xmlResultName的值等于XML document根元素的名称。例如:
XML code
<select id="getPerson" parameterClass=”int” resultClass="xml" xmlResultName=”person”>
SELECT PER_ID as id,
PER_FIRST_NAME as firstName,
PER_LAST_NAME as lastName,
PER_BIRTH_DATE as birthDate,
PER_WEIGHT_KG as weightInKilograms,
PER_HEIGHT_M as heightInMeters
FROM PERSON
WHERE PER_ID = #value#
</select>


上面的查询结果将产生一个XML document,结构如下:
XML code

<person>
<id>1</id>
<firstName>Clinton</firstName>
<lastName>Begin</lastName>
<birthDate>1900-01-01</birthDate>
<weightInKilograms>89</weightInKilograms>
<heightInMeters>1.77</heightInMeters>
</person>





产生问题:如果id值为null的时候,查询结果产生的XML document中少了id那一列,这一列怎么才能出现在xml文件中?不能在sql中加case when 因为数据量很大,估计几10万的数据,字段可能有几百个。在不影响sql执行效率的前提下如何处理?跪求各位高手


XML code
<person>
<firstName>Clinton</firstName>
<lastName>Begin</lastName>
<birthDate>1900-01-01</birthDate>
<weightInKilograms>89</weightInKilograms>
<heightInMeters>1.77</heightInMeters>
</person>




------解决方案--------------------
<select id="getPerson" parameterClass=”int” resultClass="xml" xmlResultName=”person”>
SELECT isnull(PER_ID,0) as id,
PER_FIRST_NAME as firstName,
PER_LAST_NAME as lastName,
PER_BIRTH_DATE as birthDate,
PER_WEIGHT_KG as weightInKilograms,
PER_HEIGHT_M as heightInMeters
FROM PERSON
WHERE PER_ID = #value#
</select>
------解决方案--------------------
1楼已经提出了解决方案
------解决方案--------------------
不改sql只能自己扩展ibatis了