zoukankan      html  css  js  c++  java
  • 一对多,多对一查询

            <!--一对多操作-->
            <!--resultMap一对多的关系或多对一的关联映射-->
            <resultMap id="rmGoods" type="com.imooc.mybatis.entity.GoodsEntity">
                <!--主键-->
                <id property="goodsId" column="goods_id"/>
                <!--collection 一对多的多数据集合select选择多的对象-->
                <!--collection的含义是在sql查询等到结果后代入到goodsDetail名称空间selectGoodsById的SQL中,
                并将得到的结果集合赋值到Goods对象goodDetialList 属性中-->
                <collection property="goodDetialList" select="goodsDetail.selectGoodsById" column="goods_id"/>
            </resultMap>
            <select id="selectOneToMany" resultMap="rmGoods">
                select * from t_goods limit 0,1
            </select>


    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="goodsDetail">
        <select id="selectGoodsById" parameterType="integer" resultType="com.imooc.mybatis.entity.GoodsDetailEntity">
            select * from t_goods_detail where goods_id=#{goodsId}
        </select>
        
        <!--多对一-->
        <resultMap id="rmGoodsDetail" type="com.imooc.mybatis.entity.GoodsDetailEntity">
            <id property="gdId" column="gd_id"/>
            <result property="goodsId" column="goods_id"/>
            <association property="goodsEntity" select="goods.findOneById" column="goods_id"/>
        </resultMap>
        <select id="selectManyToOne" resultMap="rmGoodsDetail">
            select * from t_goods_detail limit 0,1
        </select>
    </mapper>
  • 相关阅读:
    Python获取网页指定内容(BeautifulSoup工具的使用方法)
    python beautifulsoup 对html 进行爬取分类(部分)
    字典
    爬虫是什么
    pandas之DataFrame
    pandas之Ndarray
    pandas之Series
    爬取英文名详细内容
    python数据库连接
    python爬取昵称并保存为csv
  • 原文地址:https://www.cnblogs.com/wuheng-123/p/13838797.html
Copyright © 2011-2022 走看看