1. 程式人生 > >mybatis查詢返回的物件不為null,但是屬性值為null

mybatis查詢返回的物件不為null,但是屬性值為null

返回的物件不為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"