Mybatis 总结
生活随笔
收集整理的這篇文章主要介紹了
Mybatis 总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.如何傳遞多個參數
?mybatis中,如果接口有多個參數,那么在mapper.xml中,可以通過#{0,jdbcType=VARCHAR},#{1,jdbcType=VARCHAR}或#{param1,jdbcType=VARCHAR},#{param2,jdbcType=VARCHAR}來獲取。
2.加強版的分支、選擇判斷
<select id="findActiveBlogLike"resultType="Blog">SELECT * FROM BLOG WHERE state = ‘ACTIVE’<choose><when test="title != null">AND title like #{title}</when><when test="author != null and author.name != null">AND author_name like #{author.name}</when><otherwise>AND featured = 1</otherwise></choose> </select>3.避免Where 空條件的尷尬
<select id="findActiveBlogLike" resultType="Blog">SELECT * FROM BLOG<where><if test="state != null">and state = #{state}</if></where> </select>4.$與#的區別
1 select * from T_PRINT_LAYOUT where D_RECID = ${recId}最后生成的SQL為:
1 select * from T_PRINT_LAYOUT where D_RECID = 1即:直接將參數值替換到了原來${recId}的位置,相當于硬拼SQL
1 select * from T_PRINT_LAYOUT where D_RECID = #{recid,jdbcType=DECIMAL}最后生成的SQL為:
1 select * from T_PRINT_LAYOUT where D_RECID = ?即:#{...}被識別為一個SQL參數
?
參考:mybatis 使用經驗小結
轉載于:https://www.cnblogs.com/Gyoung/p/5540546.html
總結
以上是生活随笔為你收集整理的Mybatis 总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VirtualAllocEx 跨进程读写
- 下一篇: (王道408考研数据结构)第二章线性表-