Ребята здравствуйте! при запросе список групп выводится HTML странице так: ID Surname Firsname Patronomic Group 1 Adel Beisenbina Korganbekovna Group(groupId=1, nameGroup=7A); ... как убрать "Group(groupId=1, nameGroup=" и оставить только 7А? Вот класс Student: public class Student implements Serializable { @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "student_id", unique = true) private Long studentID; @Column(name = "firstname") private String firstname; @Column(name = "surname") private String surname; @Column(name = "patronymic") private String patronymic; @ManyToMany(fetch = FetchType.LAZY, mappedBy = "studentSet") private Set<Lesson> lessonSet = new HashSet<>(); @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "group_id") private Group group; public Student(String surname, String firstname, String patronymic) { this.firstname = firstname; this.surname = surname; this.patronymic = patronymic; } public void addLesson(Lesson lesson){ getLessonSet().add(lesson); } public void removeLesson(Lesson lesson){ getLessonSet().remove(lesson); } } класс Group: @NoArgsConstructor @Data @Entity @Table(name = "group_") @NamedQuery(name = "Group.findByName", query = "select distinct c from Group c where c.nameGroup = :name") public class Group implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "group_id", unique = true) private Long groupId; @Column(name = "name_group") private String nameGroup; public Group(String nameGroup) { this.nameGroup = nameGroup; } Вот запрос: @NamedQuery(name = "Student.findAll", query = "select c from Student c"), |
2 answers
And where to display the data? If in a string, you need to override the toString () method in the Group object.
@Override toString(){return nameGroup;} - display html page. toString is overridden by annotation. - Bazarbay Tulenov
- On the provided example, there is no Group object and a file in which data is displayed on the page. Could you attach these files to resolve your issue. - Z.John
|
I've done everything! just call group.getName () inside the tag
|