category_id 的設置

category_id 的設置

<!--结果映射-->
<resultMap id="rmGoods" type="com.imooc.mybatis.dto.GoodsDTO">
    <!--设置主键字段与属性映射-->
    <id property="goods.goodsId" column="goods_id"></id>
    <!--设置非主键字段与属性映射-->
    <result property="goods.title" column="title"></result>
    <result property="goods.originalCost" column="original_cost"></result>
    <result property="goods.currentPrice" column="current_price"></result>
    <result property="goods.discount" column="discount"></result>
    <result property="goods.isFreeDelivery" column="is_free_delivery"></result>
    <result property="goods.categoryId" column="category_id"></result>
    
    <result property="category.categoryId" column="category_id"></result>
    
    <result property="category.categoryName" column="category_name"></result>
    <result property="category.parentId" column="parent_id"></result>
    <result property="category.categoryLevel" column="category_level"></result>
    <result property="category.categoryOrder" column="category_order"></result>

    <result property="test" column="test"/>
</resultMap>

<result property="category.categoryId" column="category_id"></result>

關於category.categoryId的映射是否也需要用主鍵的方式 <id .......>?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小尤 2020-08-11 17:37:33

同学你好,在此查询中category.categoryId是条件,所以并不需要设置为主键,不过同学将category.categoryId设置为主键,也不会影响运行。

祝学习愉快!

  • 老师说的这个条件是什么意思呀?good.goodsId不是条件吗

    2020-12-02 08:47:13
  • 同学你好,1. 老师描述的条件是where条件,category.categoryId作为条件进行查询,所以可以不设置为主键。如下图所示:

    http://img1.sycdn.imooc.com//climg/5fc6f1e8099e3fbf11800518.jpg

    2. 同学描述的good.goodsId并不是条件。在上方sql语句中,是查询good表中全部的字段与category表中category_name字段,以category_id作为条件,进行查询。

    ​    查询出结果为,good表中与category表中category_id值一样的数据进行展示。所以是以good进行查询的。所以good表id需要设置为主键。

    祝学习愉快!

    2020-12-02 09:55:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师