MyBatis逆向工程关联查询表信息

1、写一个扩展类,不要用原来的,可能会影响别的代码

public class Goods2 extends Goods{
    private Type type;
    private Goods2 goods2;

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public Goods2 getGoods2() {
        return goods2;
    }

    public void setGoods2(Goods2 goods2) {
        this.goods2 = goods2;
    }

}

2、写sql语句,修改mapper.xml文件

<resultMap id="Goods2" type="com.edu.zzti.bean.Goods2">
        <result column="tid" property="tid"></result>
        <association property="type" select="com.edu.zzti.dao.TypeMapper.selectByPrimaryKey" column="tid"></association>
    </resultMap>
    <select id="selectGoods2" resultMap="Goods2">
        select * from goods where uid=#{uid}
    </select>
   

其中resultMap中association的各个属性的含义:

                property:映射数据库列的字段或属性,即指定要关联的属性名。

               colum:数据库的列名或者列标签别名。

               javaTyp:完整java类名或别名。

               jdbcType支持的JDBC类型列表列出的JDBC类型。这个属性只在insert,update或delete的时候针对允许空的列有用。

              resultMap: 一个可以映射联合嵌套结果集到一个适合的对象视图上的ResultMap。这是一个替代的方式去调用另一个select语句。
3、写Mapper接口

 List<Goods2> selectGoods2(@Param("uid") String uid);

4、前端调用

<td th:text="${li.type.tname}">

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值