我的配置文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="tablenewsandkind">
<typeAlias alias="tablenews" type="com.zzxy.po.TableNews" />
<typeAlias alias="tablenewskind" type="com.zzxy.po.TableNewsKind" />
<resultMap class="tablenews" id="TableNewsResult">
<result column="ID" jdbcType="DECIMAL" property="id" />
<result column="KIND_ID" property="kind"
select="tablenewsandkind.getKindById" />
<result column="TITLE" jdbcType="VARCHAR" property="title" />
<result column="CONTENT" jdbcType="VARCHAR" property="content" />
<result column="ITIME" jdbcType="VARCHAR" property="itime" />
<result column="IFROM" jdbcType="VARCHAR" property="ifrom" />
<result column="ADDRESS" jdbcType="VARCHAR" property="address" />
<result column="IMG" jdbcType="VARCHAR" property="img" />
<result column="ISSTATIC" jdbcType="VARCHAR"
property="isstatic" />
<result column="ISPASS" jdbcType="VARCHAR" property="ispass" />
</resultMap>
<resultMap class="tablenewskind" id="TableNewsKindResult">
<result column="ID" jdbcType="DECIMAL" property="id" />
<result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="DESP" jdbcType="VARCHAR" property="desp" />
<result column="ID" property="news"
select="tablenewsandkind.getNewsByKindId" />
</resultMap>
<select id="getAllNews" resultMap="TableNewsResult">
<![CDATA[
select ID, KIND_ID, TITLE, CONTENT, ITIME, IFROM, ADDRESS, IMG, ISSTATIC, ISPASS from TABLE_NEWS
]]>
</select>
<select id="getKindById" resultClass="tablenewskind">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
</select>
<select id="getAllKind" resultMap="TableNewsKindResult">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND
]]>
</select>
<select id="getNewsByKindId" resultMap="TableNewsResult">
<![CDATA[
select ID, KIND_ID, TITLE, CONTENT, ITIME, IFROM, ADDRESS, IMG, ISSTATIC, ISPASS from TABLE_NEWS where KIND_ID = #value#
]]>
</select>
</sqlMap>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="tablenewsandkind">
<typeAlias alias="tablenews" type="com.zzxy.po.TableNews" />
<typeAlias alias="tablenewskind" type="com.zzxy.po.TableNewsKind" />
<resultMap class="tablenews" id="TableNewsResult">
<result column="ID" jdbcType="DECIMAL" property="id" />
<result column="KIND_ID" property="kind"
select="tablenewsandkind.getKindById" />
<result column="TITLE" jdbcType="VARCHAR" property="title" />
<result column="CONTENT" jdbcType="VARCHAR" property="content" />
<result column="ITIME" jdbcType="VARCHAR" property="itime" />
<result column="IFROM" jdbcType="VARCHAR" property="ifrom" />
<result column="ADDRESS" jdbcType="VARCHAR" property="address" />
<result column="IMG" jdbcType="VARCHAR" property="img" />
<result column="ISSTATIC" jdbcType="VARCHAR"
property="isstatic" />
<result column="ISPASS" jdbcType="VARCHAR" property="ispass" />
</resultMap>
<resultMap class="tablenewskind" id="TableNewsKindResult">
<result column="ID" jdbcType="DECIMAL" property="id" />
<result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="DESP" jdbcType="VARCHAR" property="desp" />
<result column="ID" property="news"
select="tablenewsandkind.getNewsByKindId" />
</resultMap>
<select id="getAllNews" resultMap="TableNewsResult">
<![CDATA[
select ID, KIND_ID, TITLE, CONTENT, ITIME, IFROM, ADDRESS, IMG, ISSTATIC, ISPASS from TABLE_NEWS
]]>
</select>
<select id="getKindById" resultClass="tablenewskind">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
</select>
<select id="getAllKind" resultMap="TableNewsKindResult">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND
]]>
</select>
<select id="getNewsByKindId" resultMap="TableNewsResult">
<![CDATA[
select ID, KIND_ID, TITLE, CONTENT, ITIME, IFROM, ADDRESS, IMG, ISSTATIC, ISPASS from TABLE_NEWS where KIND_ID = #value#
]]>
</select>
</sqlMap>
情况是这样的:
我用上面的id=getKindById查询时取不出来news(news为List类型),代码如下:
<select id="getKindById" resultClass="tablenewskind">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
但是我把这部分换成如下:
<select id="getKindById" resultMap="TableNewsKindResult">
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
</select>
<![CDATA[
select ID, NAME, DESP from TABLE_NEWS_KIND where ID = #value#
]]>
</select>
可以取出来news,也就是说,当返回结果为resultMap时可以取出来news。
这个问题是怎么回事,请各位不吝赐教。