SpringBoot 1.5 + JDK1.8 + Mybatis3.4sql
使用Mybatis動態SQL查詢數據後發現,時間字段顯示爲null,這不單單是時間格式問題。post
跟蹤代碼以後發現xml文件中測試
映射關係url
<resultMap id="PcmArticleListDTO" type="com.xxx.xxx.model.PcmArticleListDTO"> <!-- WARNING - @mbg.generated --> <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>
動態SQLcode
<sql id="selectArticleByIdField">${alias}.CT_ID,${alias}.TITLE,${alias}.SUBTITLE,${alias}.CON,${alias}.CON_H5,${alias}.ABSTRACT,${alias}.AUTHOR,${alias}.KW,${alias}.IS_AUTODIS,${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 </sql> <select id="selectArticleById" resultType="com.bjbde.trade.model.PcmArticleListDTO"> select <include refid="selectArticleByIdField"><property name="alias" value="t1"></property></include> from PCM_ARTICLE t1 where t1.PUB_STATE = '1' and t1.DEL_TAG = '0' and t1.CT_ID = #{ctId}
SQL中select後面的域中沒有時間相應的字段,故予以添加,添加後顯示效果orm
"ctTime": 1551024000000,
這個是因爲時間格式未做處理的結果xml
找到相應的POJO在對應時間屬性上加註解接口
@JSONField(format = "yyyy-MM-dd HH:mm") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
總體效果rem
@JSONField(format = "yyyy-MM-dd HH:mm") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") private Date ctTime;
加上以後,postman從新測試接口,時間格式顯示正確。it