<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >### 1.屬性名和數據庫中的列名不同時,可以使用別名查詢 ~~~ 例如列名是name 而屬性名是e_name <select id="getAllEmp" resultType="cn.li.pojo.Employee"> select id,name e_name,gender,address from employee </select> ~~~ >#### 屬性名和數據庫中的列名不同時或者另一種方法: ~~~ <!-- 自定義封裝規則 。resultMap="" column 表示數據庫中查詢的字段名稱 。 --> <resultMap type="cn.li.pojo.Employee" id="rm2"> <!-- 使用id標簽 來指定主鍵的封裝規則 ,mybatis會做優化 。 --> <id column="id" property="id"></id> <result column="name" property="e_name" /> <result column="gender" property="gender" /> <result column="address" property="address" /> </resultMap> <select id="getAllEmp2" resultMap="rm2"> select id,name,gender,address from employee </select> ~~~ >### 2.級聯封裝 ~~~ <resultMap type="cn.li.pojo.Employee" id="rm3"> <id column="id" property="id" /> <result column="name" property="e_name" /> <result column="gender" property="gender" /> <result column="address" property="address" /> <result column="d_id" property="dept.dId" /> <result column="d_name" property="dept.dName" /> </resultMap> <select id="sel1" resultMap="rm3"> select e.*,d.* from employee e left join department d on e.d_id=d.d_id </select> ~~~ >### 3.使用聯合標簽配置,添加property,javaType屬性 ~~~ <resultMap type="cn.li.pojo.Employee" id="rm4"> <id column="id" property="id" /> <result column="name" property="e_name" /> <result column="gender" property="gender" /> <result column="address" property="address" /> <!-- 聯合 。 association 指向的是 實體類中的那個屬性 需要做聯合 配置。 --> <association property="dept" javaType="cn.li.pojo.Department"> <id column="d_id" property="dId" /> <result column="d_name" property="dName" /> </association> </resultMap> <select id="sel2" resultMap="rm4"> select e.*,d.* from employee e left join department d on e.d_id=d.d_id </select> public class Employee{ ... private Department dept; .... } ~~~ >### 4.分步查詢&延遲加載 ~~~ <!-- com/igeek/pojo/EmployeeMapper.xml 分布查詢 。。。 1.知道員工的id ,根據員工的id能拿到部門id . 2.再根據得到部門id,去查詢部門所有信息。 --> <resultMap type="cn.li.pojo.Employee" id="selStep"> <id column="id" property="id" /> <result column="name" property="e_name" /> <result column="gender" property="gender" /> <result column="address" property="address" /> <!-- association 聯合 property 要為實體類中的哪一個屬性進行賦值。 select 表示當前的這個屬性值 是通過查詢拿到的 。(通過那個命名空間下的那一個標簽去做查詢 。) column 表示 第一次查詢的哪一個列的結果作為參數傳遞給你第二次要調用的方法。 步驟1 : id name gender address d_id 1 張全蛋 1 暴走大事件 ( 1 ) 步驟2 : d_id dId,d_name dName ( 1 ) 開發 。 多個參數的分步查詢 。 #{id},#{name},#{age} column="{name=d_name,id=d_id}"; 只有分步查詢可以做延遲加載 懶加載 按需加載 。 --> <!-- select部門映射文件的namespace.標簽id --> <association property="dept" select="cn.li.dao.DepartmentDao.selDepartmentByID" column="d_id"><!-- column表示將查詢中那一列的結果作為參數傳遞給另外一個查詢 --> </association> </resultMap> <select id="sel3" resultMap="selStep"> select * from employee where id=#{id} </select> //DepartmentMapper.xml文件里的內容 <select id="selDepartmentByID" resultType="cn.li.pojo.Department"> select d_id dId,d_name dName from department where d_id=#{id} </select> //開啟延遲加載 只需要在配置文件中進行全局配置(兩個值。) //延遲加載,又叫懶加載,按需加載 lazyLoadingEnable設置為true ,aggressiveLazyLoading 設置為false ~~~ 開啟懶加載步驟: 1.導入三個jar包 ![](https://box.kancloud.cn/6b1a32759a2578e4d63a7ba4743f7489_202x62.png) 2.在全局配置文件里配置 也就是config.xml文件里 ~~~ <settings> <setting name="lazyLoadingEnabled" value="true"></setting> <setting name="aggressiveLazyLoading" value="false"></setting> </settings> ~~~ >### 5.使用collection查詢 ~~~ //一對多 查詢部門下的所有的員工信息。 <resultMap type="cn.li.pojo.Department" id="selMap2"> <id column="d_id" property="dId"/> <result column="d_name" property="dName"/> <!-- collection定義關聯集合類型的屬性的封裝規則 ofType:指定集合里面元素的類型 --> <collection property="emps" ofType="cn.li.pojo.Employee"> <id column="id" property="id"/> <result column="name" property="e_name"/> <result column="gender" property="gender"/> <result column="address" property="address"/> </collection> </resultMap> <select id="selDep" resultMap="selMap2"> select e.*,d.* from employee e left join department d on e.d_id=d.d_id where d.d_id=#{id} </select> public class Department{ ... private List<Employee> emps; ... } ~~~ ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看