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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                查詢一個 student 并查詢多個 score。 <br/> 步驟如下: **1. 在 Student 中放一個`List<Score>`** ```java @Data @NoArgsConstructor @AllArgsConstructor public class Score { private Integer id; private Integer studentId; private String subjectName; private Float subjectScore; } @Data @NoArgsConstructor @AllArgsConstructor public class Student { private Integer id; private String name; private Date born; private String gender; /** 在Student 中放一個 List<Score>,或者Set<Secore> */ private List<Score> scoreList; } ``` **2. DAO 層接口** ```java public interface StudentDao { Student findByStudentId(@Param("id") Integer id); } ``` **3. XML 映射文件** 共有兩種寫法:一種是嵌套結果查詢,一種是嵌套查詢。 (1)嵌套結果查詢。 多張表同時查詢,所以只查詢一次就可以,效率要高于嵌套查詢。 ```xml <!-- resultMap: 對應id="studentMap" 的 resultMap 標簽--> <select id="findByStudentId" resultMap="studentMap" parameterType="integer"> select st.id as student_id,st.name,st.born,st.gender, sc.id as score_id, sc.subject_name,sc.subject_score from student st inner join score sc on st.id=sc.student_id where st.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" /> <!-- Score的映射部分 property: 對應 Student.scoreList 變量名 ofType: 對應 Student.scoreList 集合存儲的變量類型 --> <collection property="scoreList" ofType="Score"> <!-- property 對應 Score 的變量名;column 對應查詢語句中的字段名--> <id property="id" column="score_id" /> <result property="studentId" column="student_id" /> <result property="subjectName" column="subject_name" /> <result property="subjectScore" column="subject_score" /> </collection> </resultMap> ``` >[warning]注意:resultMap 標簽中當映射多個實體類時,`<id column="col_name"/>`中的 col_name 是不能相同的,否則只會查詢出第一條數據。 **4. 測試** ```java @Test public void findByStudentId() { try { sqlSession = MybatisUtils.createConnetion(); Student student = sqlSession.getMapper(StudentDao.class).findByStudentId(5); System.out.println(student); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` ![](https://img.kancloud.cn/b1/1e/b11ecccf15e1dc3e00a65741ccb270ab_1542x260.jpg)
                  <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>

                              哎呀哎呀视频在线观看