sql执行,可以查询出一条数据,但是通过mybatis如下方式,返回的确实null,为什么呀?

 <select id="selectManualStat" parameterType="java.lang.String" resultType="com.sunyard.monitor.domain.General"
            resultMap="callHour">
        select sum(n_abandoned) n_abandoned,
        sum(n_answered) n_answered
        from GEN_ETL.R_GRQU_CR_1_HOUR@TO_CCGENESYS t1
        left join GEN_ETL.O_GRQU_CR_1_HOUR@TO_CCGENESYS t2
        on t1.object_id = t2.object_id
        where t2.object_name in
        <choose>
            <when test="opt == 0">
                ('GRQU_ALL')
            </when>
            <otherwise>
                ('ZH_MM','XYK_MM')
            </otherwise>
        </choose>
        and substr(time_key, 1, 8) = #{qdate}
        group by substr(time_key, 1, 8)
    </select>
<resultMap id="callHour" type="com.sunyard.monitor.domain.General">
        <result column="n_abandoned" property="n_abandoned"/>
        <result column="n_answered" property="n_answered"/>
    </resultMap>
@Data
public class General {
    private  String callhour;
    private  int n_abandoned;
    private  int n_answered;

}

阅读 2.3k
2 个回答

mybatis好久不用了,但是粗略一看,貌似你这条件那里写的应该有问题吧,object_name = 0的时候是一个值,但是else那里,你应该是想用in的吧,
你可以把object_name = 放到条件里面去

    where 
    <choose>
        <when test="opt == 0">
            t2.object_name ='GRQU_ALL'
        </when>
        <otherwise>
            t2.object_name in('ZH_MM','XYK_MM')
        </otherwise>
    </choose>
    

具体你这个问题只能是去调试sql了,代码里面selectManualStat方法执行前,先打印gdate和opt参数具体值,然后替换 mybatis里面的数据项,放到数据库再去执行看看

打印mybatis执行的SQL对比即可

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题