一、思路1:在service封装通过list的组合,强烈不建议,有性能问题,例如:
@Autowired
private StudentDao studentDao;
@Autowired
private Stu_labelDao stu_labelDao;
@Autowired
private CityDao cityDao;
@Autowired
private ClazzDao clazzDao;
@Autowired
private GroupDao groupDao;
@Autowired
private LabelDao labelDao;
@Test
public void testQuesyAllStudent(){
List<Student> students = studentDao.selectAll();
for (Student student:students){
//通用Mapper的dao方法 select(Object o),根据对象非空属性做条件查询查询
//city属性
List<City> cities = cityDao.select(student.getCity());
City city = cities.get(0);
student.setCity(city);
//clazz属性
List<Clazz> clazzes = clazzDao.select(student.getClazz());
Clazz clazz = clazzes.get(0);
student.setClazz(clazz);
//group属性
List<Group> groups = groupDao.select(student.getGroup());
Group group = groups.get(0);
student.setGroup(group);
//label集合
Stu_label stu_label = new Stu_label();
stu_label.setSid(student.getId());
List<Stu_label> stu_labels = stu_labelDao.select(stu_label);
List<Label> labels = new ArrayList<>();
for (Stu_label s:stu_labels){
Label label = labelDao.selectByPrimaryKey(s.getLid());//主键策略,根据主键查询
labels.add(label);
}
student.setLabels(labels);
}
}