zoukankan      html  css  js  c++  java
  • mybatis关联查询举例

    1、配置resultMap:

     <resultMap id="BaseResultMap" type="cn.iautos.manager.entity.mybatis.MallSafeguardService" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="safeguard_id" property="safeguardId" jdbcType="INTEGER" />
        <result column="service_id" property="serviceId" jdbcType="INTEGER" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="isdel" property="isdel" jdbcType="TINYINT" />
        这个是主要的配置。如果两个表中的字段名称相同则会出现数据异常。解决方法,可以使用别名的形式,对相同的字段赋值
        <association property="service" column="id" javaType="cn.iautos.manager.entity.mybatis.MallService" resultMap="cn.iautos.manager.repository.MallServiceDAO.BaseResultMap"/>
        
      </resultMap>
    

     2、查询语句:

     <select id="selectSafeServiceBySafeId" resultMap="BaseResultMap" parameterType="cn.iautos.manager.entity.mybatis.MallSafeguardService" >
        
        SELECT mss.*,ms.* from mall_safeguard_service mss LEFT JOIN mall_service ms on mss.service_id = ms.id where mss.safeguard_id=#{safeguardId}
      
      </select>
    
  • 相关阅读:
    CF 1119 题解
    CF 582 题解
    CF 1098 题解
    CF 1129 题解
    CF 513 题解
    CF 417 D 题解
    ingress nginx遇到502错误,connect() failed (113 Host is unreachable) while connecting to upstream
    MySQL性能剖析
    MySQL的基准测试
    MySQL架构与历史
  • 原文地址:https://www.cnblogs.com/xuzhenmin/p/3601024.html
Copyright © 2011-2022 走看看