<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之旅 廣告
                傳遞兩個,或兩個以上個數的參數可以將 DAO 層中的接口方法的參數列表聲明為 Map、@Param、實體類之一來達到傳遞參數的目的。 [TOC] # 1. 使用`java.util.Map`聲明參數列表 **1. DAO層接口** ```java public interface StudentDao { /** * 查詢性別相同,并且出生日期相同的所有學生 */ List<Student> queryByBornAndGender(Map<String, Object> params); } ``` **2. XML映射文件** ```xml <!-- #{born}、#{gender} 中的 born、gender 為 Map 中的 key --> <select id="queryByBornAndGender" parameterType="Map" resultType="Student"> select id, `name`, born, gender from student where born=#{born} and gender=#{gender} </select> ``` **3. 測試** ```java @Test public void queryByBornAndGender() { try { Map<String, Object> params = new HashMap<>(1); params.put("gender", "男"); params.put("born", new Date()); sqlSession = MybatisUtils.createConnetion(); List<Student> students = sqlSession.getMapper(StudentDao.class).queryByBornAndGender(params); System.out.println(students); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` <br/> # 2. 使用注解`@Param`聲明參數列表 **1. DAO層接口** ```java public interface StudentDao { /** * 查詢性別相同,并且出生日期相同的所有學生 */ List<Student> queryByBornAndGender2(@Param("gender") String gender, @Param("born") Date born); } ``` **2. XML映射文件** ```xml <select id="queryByBornAndGender2" resultType="Student"> select id, `name`, born, gender from student where born=#{born} and gender=#{gender} </select> ``` **3. 測試** ```java @Test public void queryByBornAndGender2() { try { sqlSession = MybatisUtils.createConnetion(); List<Student> students = sqlSession.getMapper(StudentDao.class).queryByBornAndGender2("張三", new Date()); System.out.println(students); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` <br/> # 3. 使用實體類聲明參數列表 **1. DAO層接口** ```java public interface StudentDao { /** * 查詢性別相同,并且出生日期相同的所有學生 */ List<Student> queryByBornAndGender3(Student student); } ``` **2. XML映射文件** ```xml <!-- #{keyName}: keyName就是Student類的相關屬性名 --> <select id="queryByBornAndGender3" parameterType="student" resultType="student"> select id, `name`, born, gender from student where born=#{born} and gender=#{gender} </select> ``` **3. 測試** ```java @Test public void queryByBornAndGender3() { try { Student student = new Student(); student.setName("張三"); student.setBorn(new Date()); sqlSession = MybatisUtils.createConnetion(); List<Student> students = sqlSession.getMapper(StudentDao.class).queryByBornAndGender3(student); System.out.println(students); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` <br/> # 4. 實體類與注解`@Param`配合使用 **1. DAO層接口** ```java public interface StudentDao { /** * 查詢性別相同,并且出生日期相同的所有學生 */ List<Student> queryByBornAndGender4(@Param("stu") Student student); } ``` **2. XML映射文件** ```xml <!-- stu.born 中的 stu 為 @Param 中的 stu,born為實體類 Student 中的屬性名 --> <select id="queryByBornAndGender4" parameterType="student" resultType="student"> select id, `name`, born, gender from student where born=#{stu.born} and gender=#{stu.gender} </select> ``` **3. 測試** ```java @Test public void queryByBornAndGender4() { try { Student student = new Student(); student.setName("張三"); student.setBorn(new Date()); sqlSession = MybatisUtils.createConnetion(); List<Student> students = sqlSession.getMapper(StudentDao.class).queryByBornAndGender4(student); System.out.println(students); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ``` **** 參考文檔:https://mybatis.org/mybatis-3/zh/sqlmap-xml.html#Parameters
                  <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>

                              哎呀哎呀视频在线观看