ibatis学习 : xml配置 -- 级联查询

刚学习ibatis,xml配置的级联查询做个记录

 

MalltShopCategory.xml

<typeAlias alias="malltShopCategory" type="com.sitech.item.bean.MalltShopCategory"/>
	
	<resultMap id="result1" class="malltShopCategory">
		<result property="shop_category_id" column="shop_category_id"
			columnIndex="1" jdbcType="LONG" />
		<result property="shop_id" column="shop_id" jdbcType="VARCHAR" />
		<result property="shop_category_name"
			column="shop_category_name" jdbcType="VARCHAR" />
		<result property="state" column="state" jdbcType="VARCHAR" />
		<result property="add_user" column="add_user"
			jdbcType="VARCHAR" />
		<result property="add_time" column="add_time" jdbcType="DATE" />
		<result property="update_user" column="update_user"
			jdbcType="VARCHAR" />
		<result property="update_time" column="update_time"
			jdbcType="DATE" />
<!-- 		<result property="malltMdlCsShpCtgry" column="shop_category_id"
			select="getTEST"/>  -->
	</resultMap>

<resultMap id="result2" class="com.sitech.item.bean.MalltMdlCsShpCtgry">
		<result property="mdl_cs_shp_ctgry_id"
			column="mdl_cs_shp_ctgry_id" columnIndex="1" jdbcType="LONG" />
		<result property="module_case_id" column="module_case_id"
			jdbcType="LONG" />
		<result property="shop_category_id" column="shop_category_id"
			jdbcType="LONG" />
		<result property="module_template_link_id"
			column="module_template_link_id" jdbcType="LONG" />
		<result property="link_url" column="link_url"
			jdbcType="VARCHAR" />
		<result property="picture_id" column="picture_id"
			jdbcType="INT" />
		<result property="if_display" column="if_display"
			jdbcType="VARCHAR" />
		<result property="sort" column="sort" jdbcType="INT" />
		<result property="add_user" column="add_user"
			jdbcType="VARCHAR" />
		<result property="add_time" column="add_time" jdbcType="DATE" />
		<result property="update_user" column="update_user"
			jdbcType="VARCHAR" />
		<result property="update_time" column="update_time"
			jdbcType="DATE" />
	</resultMap>

<select id="queryList" resultMap="result1" parameterClass="long">
		select * from Mallt_Shop_Category msc where msc.shop_category_id = #shop_category_id#
	</select>

<select id="getTEST" resultMap="result2" parameterClass="long">
		select * from Mallt_Mdl_Cs_Shp_Ctgry where shop_category_id = #shop_category_id#
	</select>


queryForList("queryList", shop_category_id); 就可以把两张表的关联数据一次查询出来了,刚学没弄明白resultMap的作用,程序一直报错,resultMap=“” 对应的就是<resultMap>的id

 

以上是昨天做的,今天问了下别人,原来ibatis的xml文件不是像Hibernate 的xml文件是和数据库一一对应的,ibatis的这个xml可以随意定义为自己想要的结果集,MYGOD,也就是说可以把这两个resultMap写在一起,<resultMap id="xxxxxinfo">,select语句就可以合并了,select * from Mallt_Shop_Category msc ,Mallt_Mdl_Cs_Shp_Ctgry mmcsc where msc.shop_category_id = mmcsc.shop_category_id      先在这做个记录,一会去测试下

你可能感兴趣的:(ibatis学习 : xml配置 -- 级联查询)