首页 > 解决方案 > 表列有值,但执行 SELECT * FROM t_order 后,一些返回结果为空

问题描述

表中部分列有值,但在mybatis中使用select sql语句时,大部分列返回值为null。

在 mysql(Navicat) 中尝试了类似的 sql 语句,它正确显示了所有值。

映射器文件如下:

<select id="queryPageInDao" resultType="TOrder">
    SELECT * FROM t_order
    <trim prefix="WHERE " prefixOverrides="AND |OR "> 
        AND del = 0
    <if test="param1.userId != null" >
            AND  user_id = #{param1.userId,jdbcType=INTEGER}
        </if>
        <if test="param1.courseId != null" >
            AND course_id = #{param1.courseId,jdbcType=INTEGER}
        </if>
        <if test="param1.paystatus != null" >
            AND    paystatus = #{param1.paystatus,jdbcType=INTEGER}
        </if>
       <if test="param1.userEmail != null">
           AND    user_email like CONCAT('%',#{param1.userEmail},'%' ) 
       </if>
    </trim>
    <if test="param2.sortField != null and param2.sortField != ''">
        ORDER BY ${param2.sortField}  ${param2.sortDirection}
    </if>
    LIMIT #{param2.startIndex, jdbcType=INTEGER} , #{param2.pageSize, jdbcType=INTEGER} 
    </select>

返回结果如下:

[TOrder [id=38, userId=null, courseId=null, price=10.01, paystatus=0, ... del=0],

表中数据如下:

id     userId   courseId   price       del
38        45      44       10.01        0

期待这样的事情

[TOrder [id=38, userId=45, courseId=44, price=10.01, .......

标签: mysqlmybatis

解决方案


推荐阅读