<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                查詢一個 student 并查詢一個 address。 <br/> 步驟如下: **1. 在 Student 中放一個 Address** ```java @Data @NoArgsConstructor @AllArgsConstructor public class Address { private Integer id; private String studentId; private String address; } @Data @NoArgsConstructor @AllArgsConstructor public class Student { private Integer id; private String name; private Date born; private String gender; /** 在 Student 中放一個 Address 成員變量 */ private Address address; } ``` **2. DAO 層接口** ```java public interface StudentDao { Student queryByStudentId(@Param("id") Integer id); } ``` **3. XML 映射文件** 共有兩種寫法:一種是嵌套結果查詢,一種是嵌套查詢。 (1)嵌套結果查詢。 多張表同時查詢,所以只查詢一次就可以,效率要高于嵌套查詢。 ```xml <!-- resultMap: 對應id="studentMap" 的 resultMap 標簽 --> <select id="queryByStudentId" resultMap="studentMap" parameterType="integer"> select s.id as student_id,s.name,s.born,s.gender, a.id as address_id,a.address from student s inner join address a on s.id=a.student_id where s.id=#{id} </select> <!-- id: 當前 resultMap 標簽的唯一標識,名稱自定義 type: queryByStudentId方法的返回值類型 --> <resultMap id="studentMap" type="student"> <!-- Student的映射部分 --> <id property="id" column="student_id" /> <result property="name" column="name" /> <result property="born" column="born" /> <result property="gender" column="gender" /> <!-- Address的映射部分 property: 對應 Student.address 變量名 javaType: 對應 Student.address 變量類型 --> <association property="address" javaType="Address"> <!-- property: Address實體類中的成員變量名 --> <id property="id" column="address_id" /> <result property="studentId" column="student_id" /> <result property="address" column="address" /> </association> </resultMap> ``` >[warning]注意:resultMap 標簽中當映射多個實體類時,`<id column="col_name"/>`中的 col_name 是最好不要相同。 **4. 測試** ```java @Test public void queryByStudentId() { try { sqlSession = MybatisUtils.createConnetion(); Student student = sqlSession.getMapper(StudentDao.class).queryByStudentId(5); System.out.println(student); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` ![](https://img.kancloud.cn/11/27/11276bbf9cc0bbb1f254d6f3a3ae5744_1482x226.png)
                  <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>

                              哎呀哎呀视频在线观看