1编写实体类

LinkMan实体类

编写实体类的接口,CustomerDao以及LinkManDao
一对多的方法测试

导航查询
package com.itheima.test;
import com.itheima.dao.CustomerDao;
import com.itheima.dao.LinkManDao;
import com.itheima.domain.Customer;
import com.itheima.domain.LinkMan;
import com.sun.javaws.jnl.LibraryDesc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Set;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class daohangQuery {
@Autowired
private CustomerDao customerDao;
@Autowired
private LinkManDao linkManDao;
@Test //导航查询,默认使用的是延迟加载实现的
public void query1(){
Customer customer = customerDao.getOne(1l);
Set<LinkMan> linkMans = customer.getLinkMans();
for (LinkMan linkMan:linkMans){
System.out.println(linkMan);
}
}
@Test //导航查询,从多的一方查一的一方
public void query2(){
LinkMan linkMan = linkManDao.getOne(1l);
Customer customer = linkMan.getCustomer();
System.out.println(customer);
}
}
本文通过具体案例演示了一对多关系中实体类的导航查询方法,包括从一方查询多的一方以及从多的一方查询一的一方。利用Spring框架进行单元测试,展示了如何在Customer与LinkMan两个实体类间进行双向查询。
4168

被折叠的 条评论
为什么被折叠?



