@Entity
@Table (name = "lectureHall_details")
public class LectureHall {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY  )
private int id;
private String Name;
private String code;
private String description;
private int capacity;
.......
}


这就是我的LectureHall类的样子。

@Entity
@Table(name = "timeTable_details")
public class TimeTable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY  )
private int id;
@ManyToOne
private LectureHall lectureHall;
@ManyToOne
private Department department;
.....
}


这就是我的TimeTable类的样子。我想将Map的键值作为LectureHall类的属性Name。

@RequestMapping(value = {"view/{day}/lecturehalls"})
public ModelAndView viewLectureHalls(@PathVariable("day") String day) {

    List<TimeTable> lectureHalls = timeTableDao.getLectureHallsList(day);
    Map<LectureHall, List<TimeTable>> byHall = lectureHalls.stream()
                                                           .collect(Collectors.groupingBy(TimeTable::getLectureHall));

    ModelAndView mv = new ModelAndView("page");
    mv.addObject("title","TimeTable");
    mv.addObject("mondayTime",byHall);
    mv.addObject("userclickviewlecturehallarrangements",true);
    return mv;
}


我能为此做什么?

最佳答案

如果我对您的问题的解释正确,那么您想知道如何创建从LectureHalls到Strings的HashMap。这将允许您将大厅的名称存储为地图条目中的值。这是声明和实例化此映射的方法:

Map<LectureHall, String> nameMap = new HashMap();


那回答了你的问题吗?

09-30 20:00