myBitas如何多表查询

myBitas如何多表查询

      sql查询中经常会有多表查询的功能场景。


实现效果:



例如:  主表ddpk_topic      附表:  ddpk_topic_img      外键(topic_id)


实现代码:

    ddpktopic:

@Alias("ddpktopic")
public class ddpktopic {
    private Integer id;
    private String name;
    private String introduce;
    private Integer praisecount;
    private String videourl;

    private List<ddpktopicimg> ddpktopicimgs;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public Integer getPraisecount() {
        return praisecount;
    }

    public void setPraisecount(Integer praisecount) {
        this.praisecount = praisecount;
    }

    public String getVideourl() {
        return videourl;
    }

    public void setVideourl(String videourl) {
        this.videourl = videourl;
    }

    public List<ddpktopicimg> getDdpktopicimgs() {
        return ddpktopicimgs;
    }

    public void setDdpktopicimgs(List<ddpktopicimg> ddpktopicimgs) {
        this.ddpktopicimgs = ddpktopicimgs;
    }


    @Override
    public String toString() {
        return "ddpktopic{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", introduce='" + introduce + '\'' +
                ", praisecount=" + praisecount +
                ", videourl='" + videourl + '\'' +
                ", ddpktopicimgs=" + ddpktopicimgs +
                '}';
    }
}

ddpktopicimg:

@Alias("ddpktopicimg")
public class ddpktopicimg {

    private Integer id;
    private String  topic_id;
    private String  imgurl;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTopic_id() {
        return topic_id;
    }

    public void setTopic_id(String topic_id) {
        this.topic_id = topic_id;
    }

    public String getImgurl() {
        return imgurl;
    }

    public void setImgurl(String imgurl) {
        this.imgurl = imgurl;
    }

    @Override
    public String toString() {
        return "ddpktopicimg{" +
                "id=" + id +
                ", topic_id='" + topic_id + '\'' +
                ", imgurl='" + imgurl + '\'' +
                '}';
    }
}

ddpkMapper.xml:

<resultMap id="TopicResultMap" type="ddpktopic" >
		<result column="id" property="id"/>
		<result column="name" property="name"/>
		<result column="introduce" property="introduce"/>
		<result column="praisecount" property="praisecount"/>
		<result column="videourl" property="videourl"/>
		<!-- 关联查询 -->
		<!-- 关联查询话题图片-->
		<collection property="ddpktopicimgs" javaType="java.util.List" ofType="ddpktopicimg">
			<result column="imgurl" property="imgurl"/>

		</collection>
	</resultMap>


	<!--<!– 获取所有话题信息–>-->
	<select id="getAllTopic"  resultType="list"  resultMap="TopicResultMap" >
		SELECT * FROM ddpk_topic t,ddpk_topic_img t2 WHERE t.id=t2.topic_id
	</select>

	<insert id="addddpkvisitinfo"  parameterType="ddpkvisitinfo" >
		insert into ddpk_visitinfo(name,create_date) values(#{name},#{create_date});
	</insert>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕容屠苏

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值