iBatis resultClass结果变量为null

时间:2017-06-27 03:44:14

标签: mysql ibatis

抱歉,英语水平不佳, 请原谅stackoverflow。

该公司正在使用“ANT”脚本生成工具生成SQL MAPPER,使用'resultClass',返回的对象数据为空。数据库中的Sql没问题。而其他人使用相同的措辞,无法得到正确的结果。

PS:如果我不使用resultClass,只需返回一个计数来获得结果

ANT脚本:

<operation name="queryAgentLoanCount" multiplicity="many" resultClass="com.bench.common.dal.result.AgentLoanCountResult">
    <extraparams>
        <param name="agentNo" javatype="java.lang.String"/>
    </extraparams>
    <sql>
        SELECT COUNT(ID) FROM bops_agent_loan_record
    </sql>
    <sqlmap>
        <![CDATA[
        SELECT COALESCE(SUM(tt.LOAN_AMT),0) TT_AMT ,COALESCE(COUNT(t.ID),0) TT_SUM
        FROM bops_agent_loan_record t LEFT JOIN bops_loan_request tt
                ON t.REQ_NO = tt.REQ_NO
        WHERE tt.LOAN_TYPE IN ('P1024', 'P1002', 'P5060')
                AND tt.STATE IN ('SELLING', 'BACKING', 'BACKED', 'OVERDUE')
                AND t.AGENT_NO = #agentNo#
        ]]>
    </sqlmap>
</operation>

生成的SQLMAPPER:

<select id="MS-AGENT-LOAN-RECORD-QUERY-AGENT-LOAN-COUNT" resultClass="com.bench.common.dal.result.AgentLoanCountResult">
    SELECT COALESCE(SUM(tt.LOAN_AMT),0) TT_AMT ,COALESCE(COUNT(t.ID),0) TT_SUM
        FROM bops_agent_loan_record t LEFT JOIN bops_loan_request tt
                ON t.REQ_NO = tt.REQ_NO
        WHERE tt.LOAN_TYPE IN ('P1024', 'P1002', 'P5060')
                AND tt.STATE IN ('SELLING', 'BACKING', 'BACKED', 'OVERDUE')
                AND t.AGENT_NO = #agentNo#
</select>

resultClass:

public class AgentLoanCountResult extends BaseDO {

private Long ttSum;

private Double ttAmt;

public AgentLoanCountResult() {
}

public AgentLoanCountResult(Long ttSum, Double ttAmt) {
    this.ttSum = ttSum;
    this.ttAmt = ttAmt;
}

public void setTtSum(Long ttSum) {
    this.ttSum = ttSum;
}

public Long getTtSum() {
    return ttSum;
}

public Double getTtAmt() {
    return ttAmt;
}

public void setTtAmt(Double ttAmt) {
    this.ttAmt = ttAmt;
}

}

1 个答案:

答案 0 :(得分:0)

您应该在结果对象中映射列。试试这样的事情

<resultMap id="resultMapName" class="com.your.object">
    <result property="ttSum" column="TT_SUM" />
    <result property="ttAmt" column="TT_AMT" />
</resultMap>
<select id="MS-AGENT-LOAN-RECORD-QUERY-AGENT-LOAN-COUNT" resultMap="resultMapName">
    SELECT COALESCE(SUM(tt.LOAN_AMT),0) TT_AMT ,COALESCE(COUNT(t.ID),0) TT_SUM
        FROM bops_agent_loan_record t LEFT JOIN bops_loan_request tt
                ON t.REQ_NO = tt.REQ_NO
        WHERE tt.LOAN_TYPE IN ('P1024', 'P1002', 'P5060')
                AND tt.STATE IN ('SELLING', 'BACKING', 'BACKED', 'OVERDUE')
                AND t.AGENT_NO = #agentNo#
</select>