1.控制层

@GetMapping("/findDetailById2")
public Result findDetailById2(int id){
    // 调用服务查询详情
    Setmeal setmeal = setmealService.findDetailById2(id);
    // 设置图片的完整路径
    setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
    return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
}

2.业务层

@Override
public Setmeal findDetailById2(int id) {
    return setmealDao.findDetailById2(id);
}

3.xml

<select id="findDetailById2" resultMap="setmealResultMap">
    select * from t_setmeal where id=#{id}
</select>

一对多映射:

<resultMap id="setmealDetailMap" type="setmeal">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="code" column="code"/>
    <result property="helpCode" column="helpCode"/>
    <result property="sex" column="sex"/>
    <result property="age" column="age"/>
    <result property="price" column="price"/>
    <result property="remark" column="remark"/>
    <result property="attention" column="attention"/>
    <result property="img" column="img"/>
    <collection property="checkGroups" ofType="CheckGroup">
        <id property="id" column="checkgroup_id"/>
        <result property="name" column="checkgroup_name"/>
        <result property="remark" column="checkgroup_remark"/>
        <collection property="checkItems" ofType="CheckItem">
            <id property="id" column="checkitem_id"/>
            <result property="name" column="checkitem_name"/>
        </collection>
    </collection>
</resultMap>

方式2

<resultMap type="Setmeal" id="setmealResultMap">
    <id column="id" property="id"/>
    <result column="name" property="name"/>
    <result column="code" property="code"/>
    <result column="helpCode" property="helpCode"/>
    <result column="sex" property="sex"/>
    <result column="age" property="age"/>
    <result column="price" property="price"/>
    <result column="remark" property="remark"/>
    <result column="attention" property="attention"/>
    <result column="img" property="img"/>
    <collection property="checkGroups" column="id"
                select="com.itheima.health.dao.CheckGroupDao.findCheckGroupListById">
    </collection>
</resultMap>

 

 

 

4.postman

 

5.pojo

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐