mabatis 嵌套多参外部mapper查询

如果继承了 TKmybatis 就不能使用如下方法:

FbpCoaSubject .java

package com.wxy.entity.system.accounting;

import java.util.List;

import com.wxy.lib.bean.BaseEntity;

public class FbpCoaSubject{
    private String id;

    private String accountCode;

    private String accountName;

    private String sobId;
    private Short enableFlag;
    private String extData;

    private List<FbpAssistCoaRelation> assistCoaRelationList;

    ...get set

}

FbpAssistCoaRelation .java

package com.wxy.entity.system.accounting;

import com.wxy.lib.bean.BaseEntity;

public class FbpAssistCoaRelation {
    private String id;

    private String sobId;

    private String accountId;

    private String assistMeaning;

    private Short assistStatus;
    private Short enableFlag;
    private String extData;

}

FbpCoaSubjectMapper .java

package com.wxy.mapper.accounting;

import java.util.List;

import com.wxy.entity.system.accounting.FbpCoaSubject;
import com.wxy.util.BaseMapper;

public interface FbpCoaSubjectMapper extends BaseMapper<FbpCoaSubject> {

    List<FbpCoaSubject> findByCons(FbpCoaSubject fbpCoaSubject);
}

FbpCoaSubjectMapper.xml

注意 collection 的写法
参考:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#Result_Maps

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wxy.mapper.accounting.FbpCoaSubjectMapper">
   <resultMap id="BaseResultMap" type="com.wxy.entity.system.accounting.FbpCoaSubject">
      <id column="ID" jdbcType="VARCHAR" property="id" />
      <result column="ENABLE_FLAG" jdbcType="DECIMAL" property="enableFlag" />
      <result column="ACCOUNT_CODE" jdbcType="VARCHAR" property="accountCode" />
      <result column="ACCOUNT_NAME" jdbcType="VARCHAR" property="accountName" />
      <result column="SOB_ID" jdbcType="VARCHAR" property="sobId" />
      <result column="EXT_DATA" jdbcType="VARCHAR" property="extData" />
        <collection property="assistCoaRelationList" javaType="ArrayList" ofType="com.wxy.entity.system.accounting.FbpAssistCoaRelation" 
            column="{sobId=SOB_ID,accountId=ID}" select="com.wxy.mapper.accounting.FbpAssistCoaRelationMapper.findByMapCons" />
   </resultMap>

   <sql id="Base_Column_List">
      ID, CREATE_BY, CREATE_DATE, UPDATE_BY, UPDATE_DATE, ENABLE_FLAG,
      ACCOUNT_CODE, ACCOUNT_NAME, SOB_ID, EXT_DATA
   </sql>

   <select id="findByCons" parameterType="com.wxy.entity.system.accounting.FbpCoaSubject"
      resultMap="BaseResultMap">
      select <include refid="Base_Column_List" /> from FBP_COA_SUBJECT
        <where>
            <if test="sobId != null and !sobId.isEmpty()">
                SOB_ID = #{sobId}
            </if>
              <if test="accountCode != null and !accountCode.isEmpty()">
                  AND ACCOUNT_CODE = #{accountCode}
              </if>
              <if test="accountName != null and !accountName.isEmpty()">
                  AND ACCOUNT_NAME = #{accountName}
              </if>
        </where>
   </select>

</mapper>


FbpAssistCoaRelationMapper.java

package com.wxy.mapper.accounting;

import java.util.List;
import java.util.Map;

import com.wxy.entity.system.accounting.FbpAssistCoaRelation;
import com.wxy.util.BaseMapper;

public interface FbpAssistCoaRelationMapper extends BaseMapper<FbpAssistCoaRelation> {

    List<FbpAssistCoaRelation> findByMapCons(Map<String, Object> map);
}

FbpAssistCoaRelationMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wxy.mapper.accounting.FbpAssistCoaRelationMapper">
   <resultMap id="BaseResultMap" type="com.wxy.entity.system.accounting.FbpAssistCoaRelation">
      <id column="ID" jdbcType="VARCHAR" property="id" />
      <result column="ENABLE_FLAG" jdbcType="DECIMAL" property="enableFlag" />
      <result column="SOB_ID" jdbcType="VARCHAR" property="sobId" />
      <result column="ACCOUNT_ID" jdbcType="VARCHAR" property="accountId" />
      <result column="ASSIST_MEANING" jdbcType="VARCHAR" property="assistMeaning" />
      <result column="ASSIST_STATUS" jdbcType="DECIMAL" property="assistStatus" />
      <result column="EXT_DATA" jdbcType="VARCHAR" property="extData" />
   </resultMap>

   <sql id="Base_Column_List">
      ID, CREATE_BY, CREATE_DATE, UPDATE_BY, UPDATE_DATE, ENABLE_FLAG, SOB_ID,
      ACCOUNT_ID,ASSIST_MEANING, ASSIST_STATUS, EXT_DATA
   </sql>

   <select id="findByMapCons" parameterType="java.util.HashMap"
        resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> from FBP_ASSIST_COA_RELATION
          <where>
              <if test="sobId != null and !sobId.isEmpty()">
                  SOB_ID = #{sobId}
              </if>
              <if test="accountId != null and !accountId.isEmpty()">
                  AND ACCOUNT_ID = #{accountId}
              </if>
          </where>
     </select>
</mapper>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值