SpringBoot 1.5 + JDK1.8 + Mybatis3.4sql
接口測試過程當中發現,數據庫裏面好些字段有值,而postman顯示的結果爲null,並且有的字段能夠顯示有的不能夠。數據庫
List<PcmArticleListDTO> selectAboutUs(String siteId);
<sql id="selectAboutUsField">${alias}.CT_ID,${alias}.TITLE,${alias}.SUBTITLE,${alias}.CON,${alias}.CON_H5,${alias}.ABSTRACT,${alias}.AUTHOR,${alias}.CT_TIME,${alias}.KW,${alias}.IS_AUTODIS,${alias}.DIS_TIME,${alias}.AU_STATE,${alias}.PUB_STATE,${alias}.LIKE_NUM,${alias}.READ_NUM,${alias}.COVER_PATH,${alias}.CONTENT_TYP,${alias}.URL,${alias}.IS_TIMEING,${alias}.REMARK, ${alias}.CRT_TIME,${alias}.UPD_TIME,${alias}.TIMEING_DATE </sql> <select id="selectAboutUs" resultType="com.xxx.xxx.model.PcmArticleListDTO"> select <include refid="selectAboutUsField"> <property name="alias" value="t1"></property> </include> from PCM_ARTICLE t1 left join PCM_SECTION_ARTICLE t2 on t1.CT_ID = t2.CT_ID where t1.PUB_STATE = '1' and t1.DEL_TAG = '0' and t2.SEC_SID = #{siteId} order by t2.ORDER_VAL, t1.PUB_TIME desc </select>
<resultMap id="PcmArticleListDTO" type="com.xxx.xxx.model.PcmArticleListDTO"> <id column="CT_ID" jdbcType="VARCHAR" property="ctId" /> <result column="TITLE" jdbcType="VARCHAR" property="title" /> <result column="SUBTITLE" jdbcType="VARCHAR" property="subtitle" /> <result column="CON" jdbcType="VARCHAR" property="con" /> <result column="CON_H5" jdbcType="VARCHAR" property="conH5" /> <result column="ABSTRACT" jdbcType="VARCHAR" property="abstracts" /> <result column="AUTHOR" jdbcType="VARCHAR" property="author" /> <result column="CT_TIME" jdbcType="TIMESTAMP" property="ctTime" /> <result column="KW" jdbcType="VARCHAR" property="kw" /> <result column="IS_AUTODIS" jdbcType="CHAR" property="isAutodis" /> <result column="DIS_TIME" jdbcType="TIMESTAMP" property="disTime" /> <result column="AU_STATE" jdbcType="CHAR" property="auState" /> <result column="PUB_STATE" jdbcType="CHAR" property="pubState" /> <result column="DEL_TAG" jdbcType="VARCHAR" property="delTag" /> <result column="CRT_OPT" jdbcType="VARCHAR" property="crtOpt" /> <result column="CRT_TIME" jdbcType="TIMESTAMP" property="crtTime" /> <result column="UPD_OPT" jdbcType="VARCHAR" property="updOpt" /> <result column="UPD_TIME" jdbcType="TIMESTAMP" property="updTime" /> <result column="PUB_OPT" jdbcType="VARCHAR" property="pubOpt" /> <result column="PUB_TIME" jdbcType="TIMESTAMP" property="pubTime" /> <result column="LIKE_NUM" jdbcType="DECIMAL" property="likeNum" /> <result column="READ_NUM" jdbcType="DECIMAL" property="readNum" /> <result column="COVER_PATH" jdbcType="VARCHAR" property="coverPath" /> <result column="CONTENT_TYP" jdbcType="CHAR" property="contentTyp" /> <result column="URL" jdbcType="VARCHAR" property="url" /> <result column="IS_TIMEING" jdbcType="CHAR" property="isTimeing" /> <result column="TIMEING_DATE" jdbcType="TIMESTAMP" property="timeingDate" /> <result column="REMARK" jdbcType="VARCHAR" property="remark" /> </resultMap>
查看定義的pojo及對應的映射關係,沒有發現異常。app
跟以前代碼比較發現,此處返回的值使用resultMap,而此處使用的resultType,會不會是這個問題引發的?post
遂將此處的resultType,更換爲resultMap,更換以後發現,都可以正常顯示測試
resultMap:適合pojo中屬性名與數據庫表名一致或不一致的狀況,已經創建了對應關係(通過駝峯處理的字段)。 resultType:適合pojo中屬性名與數據庫表中列名徹底一致的狀況。url
對比個人測試發現,TITLE,SUBTITLE這種字段在一種狀況下能夠正常顯示,而CT_ID之類的字段則不能顯示,驗證了以上的說法。code
resultMap通用性更高,建議優先使用。xml