一对多:
MyBatis.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration SYSTEM "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!--配置--> <!--类型命名--> <typeAliases> <package name="com.entity"/> </typeAliases> <!--配置环境--> <environments default="sc"> <environment id="sc"> <!--事务管理器--> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mydb"/> <property name="username" value="root"/> <property name="password" value="123456"/> </dataSource> </environment> </environments> <mappers> <!--映射资源地址--> <mapper resource="com/dao/StudentInfo.xml"></mapper> </mappers> </configuration>
dao.xml文件eg:
Test测试类:
多对一dao.xml文件
测试类: