<mapper namespace="com.casic.smart.model.TopicNews">
<!-- 项目专区信息 -->
<resultMap id="ItemTopic" type="com.casic.smart.model.ItemTopic">
<id property="id" column="topic_id" jdbcType="NUMERIC"/>
<result property="name" column="topic_name" jdbcType="VARCHAR"/>
</resultMap>
<!-- 活动专区信息 -->
<resultMap id="ThemeTopic" type="com.casic.smart.model.ThemeTopic">
<id property="id" column="topic_id" jdbcType="NUMERIC"/>
<result property="name" column="topic_name" jdbcType="VARCHAR"/>
</resultMap>
<!-- 项目新闻信息 -->
<resultMap id="TopicNews" type="com.casic.smart.model.TopicNews">
<id property="id" column="news_id" jdbcType="NUMERIC"/>
<result property="title" column="news_title" jdbcType="VARCHAR"/>
<result property="author" column="news_author" jdbcType="VARCHAR"/>
<result property="content" column="news_content" jdbcType="VARCHAR"/>
<result property="publishTime" column="publish_time" jdbcType="DATE"/>
<result property="relateItem" column="relate_item" jdbcType="NUMERIC"/>
<result property="relateTheme" column="relate_theme" jdbcType="NUMERIC"/>
<result property="userId" column="userId" jdbcType="NUMERIC"/>
<result property="orgId" column="orgId" jdbcType="NUMERIC"/>
<result property="advice" column="advice" jdbcType="VARCHAR"/>
<result property="auditor" column="auditor" jdbcType="VARCHAR"/>
<result property="groupAdvice" column="groupAdvice" jdbcType="VARCHAR"/>
<result property="groupAuditor" column="groupAuditor" jdbcType="VARCHAR"/>
<result property="state" column="state" jdbcType="VARCHAR"/>
<!-- 定义多对一关联信息 -->
<!-- 关联的第一个对象信息:项目专区对象 select属性是关键,嵌套查询-->
<association property="relateItemTopic" column="relate_item" javaType="com.casic.smart.model.ItemTopic" select="selectRelateItemTopic"/>
<!-- 关联的第二个对象信息:活动专区对象 -->
<association property="relateThemeTopic" column="relate_theme" javaType="com.casic.smart.model.ThemeTopic" select="selectRelateThemeTopic"/>
</resultMap>
<!-- resultMap属性是关键,最初就是因为没有写这个属性,一直无法成功封装-->
<select id="selectRelateItemTopic" resultType="com.casic.smart.model.ItemTopic" resultMap="ItemTopic">
SELECT topic_id,topic_name,topic_intro
FROM zh_item_topic WHERE topic_id = #{relateItem}
</select>
<select id="selectRelateThemeTopic" resultType="com.casic.smart.model.ThemeTopic" resultMap="ThemeTopic">
SELECT topic_id,topic_name,topic_intro
FROM zh_theme_topic WHERE topic_id = #{relateTheme}
</select>
Mybatis一个对象关联两个对象(多对一)
最新推荐文章于 2024-07-22 23:51:22 发布