java小王博客

记录菜B的一点一滴,欢迎各位好汉前来叨扰!


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>博主qq:1756691861

MyBatis 使用多表联查,两张表中字段重复时,采用取别名方法解决

2020-6-10 卑微小王 SpringBoot

图1.png

product.* 里面包含了name属性,category也有name属性,所以将category.name 取了别名"category_name"



映射


<resultMap id="ResultMapSth" type="com.bmcs.mall.web.vo.ProductCateVO">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <collection property="categories" ofType="com.bmcs.mall.dal.entity.SimpleCategory">
            <result property="name" column="category_name"/>
        </collection>
    </resultMap>


mybatis


 <select id="findByPages" parameterType="com.bmcs.mall.web.vo.PageVO" resultMap="ResultMapSth">
        select product.*,category.name   "category_name"  from  product AS product INNER JOIN category AS
        category ON category.id = product.categoryid
        where product.`status`!=0
    </select>

文章来源:https://blog.csdn.net/qq_40588618/article/details/89519653?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

发表评论: