mybatis中的多對多的查詢


數據庫設計如下:

老師數據表:

學生數據表:

 

第三方表:

 

 

 

 

 

 

 

dao層接口:

/**
* 多對多
* @param tid
* @return
*/
public Teacher getStudentByTeacherId(int tid);


xml文件:





測試類:
/**
* 多對多
*/
@Test
public void getStudentByTeacherId(){
SqlSession session = MyBatisUtil.getSession();
ITeacherDAO mapper = session.getMapper(ITeacherDAO.class);
Teacher teacher = mapper.getStudentByTeacherId(1);
System.out.println("老師名字:"+teacher.getTname());
for (Student item :teacher.getStudents()){
System.out.println("學生名字:"+item.getName());
}
}


效果如下:

 

 
        
 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM