問題提出:數據庫表的列明一般是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>
mybatis解決數據庫表列明與實體不一致問題
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
SQL語句執行 -- SQL語句的生成 -- Java的StringBuffer類
jijian_jinan
2018-08-27 19:46:33
<MyBatis緩存機制>一級緩存源碼淺析
auleit
2018-08-27 19:17:02
Spring3 整合MyBatis3 配置多數據源 動態選擇SqlSessionFactory
golly_tl
2018-08-27 19:01:59
Spring3.3 整合 Hibernate3、MyBatis3.2 配置多數據源/動態切換數據源 方法
golly_tl
2018-08-27 19:01:59
Mybatis-Generator命令行自動生成代碼
季末工作室
2018-08-27 18:56:29
Mybatis基礎學習-緩存
树树在变干
2018-08-27 18:55:17
Mybatis的mapper接口函數重載問題
树树在变干
2018-08-27 18:55:16
推薦一款軟件mybatis-generator-gui
Andy2019
2018-08-27 18:53:35
mybatis自定義枚舉轉換類
Andy2019
2018-08-27 18:53:34
mybatis SQL語句複用
iiuk3
2018-08-27 18:10:29
Mybatis單張數據表CRUD操作
Rxk17805428997
2018-08-27 17:27:24
Mybatis多表連接查詢
Rxk17805428997
2018-08-27 17:27:19
Mybatis簡介及配置
Rxk17805428997
2018-08-27 17:27:19
Mybatis 通配符# 以及 $的使用
Coder_Hunter
2018-08-27 17:12:12
關於sqlsession的疑惑?
wangjie0925
2018-08-27 16:55:05