簡體   English   中英

在HashMap中將對象作為鍵值並在jsp中使用

[英]Object as a key value in HashMap and using in jsp

@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();

那回答了你的問題嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM