mapper 動態代理 注意事項

來源:互聯網
上載者:User

標籤:方法傳回值   rom   bat   integer   注意事項   oct   隔離   user   參數類型   

mapper 借口 同 dao 接頭類似

mybatis 架構 會根據  介面定義 建立介面的動態代理對象

 

mapper 介面 開發 需要遵循 4個 開發 規範

mapper中的 對應檔的 namesapce 要與mapper介面的類路徑相同

mapper 介面方法名  和 mapper對應檔中定義的每個sql 的 id 相同

mapper 介面方法的輸入參數類型 和 mapper對應檔中 每個sql 定義的paramentType 的類型相同

mapper 介面 方法的輸出參數類型和mapper 對應檔中的每個sql 定義的resultType 的類型相同

 

 

mapper 映射 檔案 UserMapper.xml 放在 resources的 mapper 目錄下

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- namespace:命名空間,用於隔離sql --><!-- 還有一個很重要的作用,使用動態代理開發DAO,1. namespace必須和Mapper介面類路徑一致 --><mapper namespace="com.itheima.mybatis.mapper.UserMapper">    <!-- 根據使用者id查詢使用者 -->    <!-- 2. id必須和Mapper介面方法名一致 -->    <!-- 3. parameterType必須和介面方法參數類型一致 -->    <!-- 4. resultType必須和介面方法傳回值類型一致 -->    <select id="queryUserById" parameterType="Integer"        resultType="com.itheima.mybatis.pojo.User">        select * from user where id = #{id}    </select></mapper>

 

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.