mybatis查询返回的对象不为null,但是属性值为null

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaogc_a/article/details/82505111

返回的对象不为null,但是属性值为null

代码如下:

 <resultMap id="BaseResultMap" type="com.trhui.ebook.dao.model.MerchantUser">
      <id column="MU_ID" jdbcType="BIGINT" property="muId"/>
      <result column="USER_ID" jdbcType="BIGINT" property="userId"/>
      <result column="MERCHANT_NO" jdbcType="VARCHAR" property="merchantNo"/>
      <result column="USER_PHONE" jdbcType="VARCHAR" property="userPhone"/>
      <result column="GRANTED" jdbcType="VARCHAR" property="granted"/>
      <result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate"/>
      <result column="MERCHANT_USER_ID" jdbcType="VARCHAR" property="merchantUserId"/>
      <result column="STATUS" jdbcType="VARCHAR" property="status"/>
      <result column="ENTE_USER_NO" jdbcType="VARCHAR" property="enteUserNo"></result>
  </resultMap>

  <sql id="Base_Column_List">
    MU_ID muId,
    USER_ID userId,
    MERCHANT_NO merchantNo,
    USER_PHONE userPhone,
    GRANTED granted,
    CREATE_DATE createDate,
    MERCHANT_USER_ID merchantUserId,
    ENTE_USER_NO enteUserNo,
    STATUS status
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from merchant_user
    where MU_ID = #{muId,jdbcType=BIGINT}
</select>

原因分析:

如果返回的对象是resultMap 那么就不要给字段加别名了,问题就是出在这里,将字段别名去了就OK;

如果要给字段加别名,那么你就直接返回该对象就好了,路径要写全,如:resultType="com.trhui.ebook.dao.model.MerchantUser"

而不是返回resultMap="BaseResultMap"

猜你喜欢

转载自blog.csdn.net/xiaogc_a/article/details/82505111