简体   繁体   中英

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;
.......
}

This is how my LectureHall class look like.

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

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

This is how my TimeTable class look like.I want to make the key value of the Map as the LectureHall class attribute 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;
}

what I can do for that?

If I interpreted your question right, you want to know how to create a HashMap from LectureHalls to Strings. This will allow you to store a hall's Name as the value in the map entry. Here is how you would declare and instantiate this map:

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

Did that answer your question?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM