ibatis多对多示例
1、iBATIS的多对多映射配置方法和多对一映射配置方法差不多,不同的是,多对多映射,数据库设计上需要一个记录两个类关系的中间表,本文以学生-老师为例,在iBATIS的sqlmap中配置多对多关系。
2、构建数据库表如下,student表,teacher表和student_teacher表:(使用mysql数据库)
student表:
配置连接数据库的资源文件:
jdbc.properties
6、执行结果如下:log4j:WARN No appenders could be found for logger (com.ibatis.common.jdbc.SimpleDataSource).log4j:WARN Please initialize the log4j system properly.name:张三birthday:1982-01-01his teachers as follows:teacher name:Jerryteacher name:Tomname:李四birthday:1983-02-02his teachers as follows:teacher name:Jerryname:王五birthday:1984-03-03his teachers as follows:teacher name:Tomname:赵六birthday:1985-04-04his teachers as follows:============================================name:Jerry subject:语文his students as follows:student name:张三student name:李四name:Tom subject:数学his students as follows:student name:张三student name:王五name:Steven subject:英语his students as follows: