ibatis开发过程中小计

在BeanA中引用BeanB对象

public class A{
 private String userId;
 private B b;
 public String getUserId() {
        return userId;
    }
 public void setUserId(String userId) {
        this.userId= userId;
    }
 public B getB() {
        return b;
    }
 public void setA(B b) {
        this.b= b;
    }
}

public class B{
private String userId;
private String name;
private String tel;
.....set \get方法
}
A_SqlMap.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="A" >
  <resultMap id="ibatorgenerated_BaseResultMap" class="portalcore.dao.vo.TUsers" >
    <!--
      WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
    -->
    <result column="A" property="userId" jdbcType="VARCHAR" />
    <result property="b" column="USER_ID"
            select="b.selectById" />
  </resultMap>
  省略
</sqlMap>

B_SqlMap.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="T_TERMINAL" >
  <resultMap id="ibatorgenerated_BaseResultMap" class="portalcore.dao.vo.TTerminal" >
    <!--
      WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
    -->
    <result column="USER_ID" property="userId" jdbcType="VARCHAR" />
    <result column="NAME" property="name" jdbcType="VARCHAR" />
    <result column="TEL" property="tel" jdbcType="VARCHAR" />

  </resultMap>
    <!--自己定义的-->
    <select id="selectById" resultMap="ibatorgenerated_BaseResultMap" parameterClass="String" >
    <!--
      WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
    -->
    select USER_ID,NAME,TEL
    from B where  USER_ID=#userId:VARCHAR#

  </select>
</sqlMap>


在查询A 的同时也查询了B



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值