mybatis學習筆記,mapper代理方法的使用

來源:互聯網
上載者:User

標籤:mybatis

一.開發人員需要完成的任務:

  mapper.xml對應檔和mapper.java

二.開發規範


    1、在mapper.xml中namespace等於mapper介面地址。

    2、mapper.java介面中的方法名和mapper.xml中statement的id一致

   3、mapper.java介面中的方法輸入參數類型和mapper.xml中statement的parameterType指定的類型一致。

    4、mapper.java介面中的方法傳回值類型和mapper.xml中statement的resultType指定的類型一致。

mapper.java樣本

//根據id查詢使用者資訊public User findUserById(int id) throws Exception;

mapper.xml樣本

<select id="findUserById" parameterType="int" resultType="user">SELECT * FROM USER WHERE id=#{value}</select>

    5、在SqlMapConfig.xml中載入mapper.xml

<!-- 通過mapper介面載入單個 對應檔   遵循一些規範:需要將mapper介面類名和mapper.xml對應檔名稱保持一致,且在一個目錄中      上邊規範的前提是:使用的是mapper代理方法 --><mappers><mapper class="cn.itcast.mybatis.mapper.UserMapper"/></mappers>

或者

<mappers><!-- 批量載入mapper指定mapper介面的包名,mybatis自動掃描包下邊所有mapper介面進行載入遵循一些規範:需要將mapper介面類名和mapper.xml對應檔名稱保持一致,且在一個目錄 中上邊規範的前提是:使用的是mapper代理方法 --><package name="cn.itcast.mybatis.mapper"/></mappers>


mybatis學習筆記,mapper代理方法的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.