mybatis解決數據庫表列明與實體不一致問題

問題提出:數據庫表的列明一般是t_userid,t_username ...
                    而我們定義的實體屬性時不能帶下劃線。這樣使我們在使用mybatis查詢時查不出來信息。


解決方案:這個是一張表我們可以加resultMap
<mapper namespace="com.myspotlight.entity.SingerMapper">
這裏面的Singer使用的時候已經在mybatis-config.xml進行了配置
<resultMap type="Singer" id="singerResultMap">
這兩個的區別 id是主鍵
<id column="s_id" property="sId" />
<result column="s_id" property="sId" />
<result column="s_name" property="sName" />
<result column="s_sex" property="sSex" />
<result column="s_birthday" property="sBirthday" />
<result column="s_type" property="sType" />
<result column="s_history" property="sHistory" />
<result column="s_achievement" property="sAchievement" />
<result column="s_message" property="sMessage" />
<result column="s_remark" property="sRemark" />
</resultMap>
resultMap 解決了列明和屬性名不匹配的問題
<select id="selectAllSinger" parameterType="Singer" resultMap="singerResultMap">
SELECT * FROM myspotlight_singer
</select>
</mapper> 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章