如果继承了 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>