คำสำคัญ: การเชื่อมโยงการทำแผนที่แบบตัวต่อตัว (ชั้นหนึ่งมีครูชั้นเรียนเพียงคนเดียว)
<select id = "getClass" parameterType = "int" resultmap = "classesResultMap"> เลือก * จากคลาส C, ครู t โดยที่ c.teacher_id = t.t_id และ c.c_id =#{id} <property = "name" column = "c_name"/> <Association property = "teacher" javatype = "com.lcb.user.teacher"> <id property = "id" คอลัมน์ = "t_id"/> <result property = "name"คำสำคัญ: คอลเลกชันการทำแผนที่แบบหนึ่งถึงหลายครั้ง (ครูหนึ่งคนมีนักเรียนหลายคน)
<resultmap type = "ครู" id = "teachermaps"> <id column = "id" คุณสมบัติ = "id"/> <result column = "name" คุณสมบัติ = "name"/> <result column = "class_name" คุณสมบัติ = "className"/> <collection property = "นักเรียน" id = "getAllTeacher" parameterType = "ครู" resultmap = "Teachermaps"> เลือก t.id, t.name, t.class_name จากครู t </select> <select id = "getStudents" parameterType = "int" resultType = "นักเรียน" ชื่อ, s.class_name เป็น classname จากนักเรียน s โดยที่ teacher_id = #{id} </select>คำหลัก: เชื่อมโยงการทำแผนที่แบบหลายต่อหนึ่ง (หลายคนอยู่ในประเทศเดียว)
หลายต่อหนึ่งนั้นเทียบเท่ากับหนึ่งถึงหลายคนและสามารถใช้คอลเลกชันได้
<select id = "SelectCountry" resultType = "Country"> เลือก CID, CNAME จากประเทศที่ cid =#{ooo} </select> <resultmap type = "people" id = "peoplemapper2"> <id column = "pid" select = "selectCountry" คอลัมน์ = "countryId"/> </resultmap> <select id = "selectById2" resultmap = "peopleMapper2"> เลือก pid, pname, countryId จากคนที่ pid = #{xxx} </select>สรุป
ข้างต้นเป็นข้อสงสัยแบบตัวต่อตัวแบบหนึ่งต่อหลายและหลายต่อหลายคนแนะนำให้คุณรู้จักโดยบรรณาธิการ ฉันหวังว่ามันจะเป็นประโยชน์กับคุณ หากคุณมีคำถามใด ๆ โปรดฝากข้อความถึงฉันและบรรณาธิการจะตอบกลับคุณทันเวลา ขอบคุณมากสำหรับการสนับสนุนเว็บไซต์ Wulin.com!