Jpa 无法显示链接关联中的值
我有一个带有JPA和Thymeleaf的Spring Boot应用程序。我无法在Jpa 无法显示链接关联中的值,jpa,spring-boot,Jpa,Spring Boot,我有一个带有JPA和Thymeleaf的Spring Boot应用程序。我无法在th模板中显示与提名.提名人.雇员.姓名等效的内容 这里需要注意的是,如果我使用提名控制器来表示提名人,则员工姓名将通过${namegate.employeepretyname}显示在其视图中 以下是POJO代码: //I am working with a NominationDraft Type instance of this class public abstract class Nomination {
th
模板中显示与提名.提名人.雇员.姓名
等效的内容
这里需要注意的是,如果我使用提名控制器来表示提名人,则员工姓名将通过${namegate.employeepretyname}
显示在其视图中
以下是POJO代码:
//I am working with a NominationDraft Type instance of this class
public abstract class Nomination {
@OneToMany
private List<Nominee> nominees;
public List<Nominee> getNominees() {
return nominees;
}
}
public class Nominee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToOne
private Nomination nomination;
@ManyToOne
private Employee employee;
public Employee getEmployee() {
return employee;
}
public String getEmployeePrettyName() { return employee.getPrettyName(); }
以下是有问题的控制器方法:
@RequestMapping(value="/nomination/{id}")
public String nomination(@PathVariable("id") Long id, Model model) {
Nomination nomination = nominationService.findById(id);
model.addAttribute("nomination", nomination);
model.addAttribute("nominees", nomination.getNominees());
return "nomination";
}
Hibernate: select nomination0_.id as id2_3_, nomination0_.user_id as user_id3_3_, nomination0_.nomination_type as nominati1_3_ from nomination nomination0_ where nomination0_.id=?
Hibernate: select user0_.id as id1_7_0_, user0_.employee_id as employee2_7_0_, employee1_.id as id1_0_1_, employee1_.email as email2_0_1_, employee1_.first_name as first_na3_0_1_, employee1_.last_name as last_nam4_0_1_, employee1_.manager_id as manager_6_0_1_, employee1_.nnumber as nnumber5_0_1_, directrepo2_.manager_id as manager_6_0_2_, directrepo2_.id as id1_0_2_, directrepo2_.id as id1_0_3_, directrepo2_.email as email2_0_3_, directrepo2_.first_name as first_na3_0_3_, directrepo2_.last_name as last_nam4_0_3_, directrepo2_.manager_id as manager_6_0_3_, directrepo2_.nnumber as nnumber5_0_3_ from user user0_ left outer join employee employee1_ on user0_.employee_id=employee1_.id left outer join employee directrepo2_ on employee1_.id=directrepo2_.manager_id where user0_.id=?
Hibernate: select nominees0_.nomination_id as nominati1_3_0_, nominees0_.nominees_id as nominees2_4_0_, nominee1_.id as id1_5_1_, nominee1_.employee_id as employee2_5_1_, nominee1_.nomination_id as nominati3_5_1_, employee2_.id as id1_0_2_, employee2_.email as email2_0_2_, employee2_.first_name as first_na3_0_2_, employee2_.last_name as last_nam4_0_2_, employee2_.manager_id as manager_6_0_2_, employee2_.nnumber as nnumber5_0_2_, employee3_.id as id1_0_3_, employee3_.email as email2_0_3_, employee3_.first_name as first_na3_0_3_, employee3_.last_name as last_nam4_0_3_, employee3_.manager_id as manager_6_0_3_, employee3_.nnumber as nnumber5_0_3_, nomination4_.id as id2_3_4_, nomination4_.user_id as user_id3_3_4_, nomination4_.nomination_type as nominati1_3_4_, user5_.id as id1_7_5_, user5_.employee_id as employee2_7_5_, employee6_.id as id1_0_6_, employee6_.email as email2_0_6_, employee6_.first_name as first_na3_0_6_, employee6_.last_name as last_nam4_0_6_, employee6_.manager_id as manager_6_0_6_, employee6_.nnumber as nnumber5_0_6_ from nomination_nominees nominees0_ inner join nominee nominee1_ on nominees0_.nominees_id=nominee1_.id left outer join employee employee2_ on nominee1_.employee_id=employee2_.id left outer join employee employee3_ on employee2_.manager_id=employee3_.id left outer join nomination nomination4_ on nominee1_.nomination_id=nomination4_.id left outer join user user5_ on nomination4_.user_id=user5_.id left outer join employee employee6_ on user5_.employee_id=employee6_.id where nominees0_.nomination_id=?
以下是视图文件:
<h1>Viewing a Nomination</h1>
<table>
<tr th:each="nominee : ${nominees}">
<td th:text="${nominee.employeePrettyName}">Pretty Name</td>
</tr>
</table>
谢谢 如果一项提名有许多被提名人,你不应该为被提名人编制索引,以便能够找到你想要的人吗 如下所示:
namignment.namegate[i].employee.name
其中i是要显示的被提名人的索引
参考资料:Fair point,但我认为thymeleaf旨在允许简单地迭代集合,而不知道要显示的每个对象的索引。这就是我使用
Hibernate: select nomination0_.id as id2_3_, nomination0_.user_id as user_id3_3_, nomination0_.nomination_type as nominati1_3_ from nomination nomination0_ where nomination0_.id=?
Hibernate: select user0_.id as id1_7_0_, user0_.employee_id as employee2_7_0_, employee1_.id as id1_0_1_, employee1_.email as email2_0_1_, employee1_.first_name as first_na3_0_1_, employee1_.last_name as last_nam4_0_1_, employee1_.manager_id as manager_6_0_1_, employee1_.nnumber as nnumber5_0_1_, directrepo2_.manager_id as manager_6_0_2_, directrepo2_.id as id1_0_2_, directrepo2_.id as id1_0_3_, directrepo2_.email as email2_0_3_, directrepo2_.first_name as first_na3_0_3_, directrepo2_.last_name as last_nam4_0_3_, directrepo2_.manager_id as manager_6_0_3_, directrepo2_.nnumber as nnumber5_0_3_ from user user0_ left outer join employee employee1_ on user0_.employee_id=employee1_.id left outer join employee directrepo2_ on employee1_.id=directrepo2_.manager_id where user0_.id=?
Hibernate: select nominees0_.nomination_id as nominati1_3_0_, nominees0_.nominees_id as nominees2_4_0_, nominee1_.id as id1_5_1_, nominee1_.employee_id as employee2_5_1_, nominee1_.nomination_id as nominati3_5_1_, employee2_.id as id1_0_2_, employee2_.email as email2_0_2_, employee2_.first_name as first_na3_0_2_, employee2_.last_name as last_nam4_0_2_, employee2_.manager_id as manager_6_0_2_, employee2_.nnumber as nnumber5_0_2_, employee3_.id as id1_0_3_, employee3_.email as email2_0_3_, employee3_.first_name as first_na3_0_3_, employee3_.last_name as last_nam4_0_3_, employee3_.manager_id as manager_6_0_3_, employee3_.nnumber as nnumber5_0_3_, nomination4_.id as id2_3_4_, nomination4_.user_id as user_id3_3_4_, nomination4_.nomination_type as nominati1_3_4_, user5_.id as id1_7_5_, user5_.employee_id as employee2_7_5_, employee6_.id as id1_0_6_, employee6_.email as email2_0_6_, employee6_.first_name as first_na3_0_6_, employee6_.last_name as last_nam4_0_6_, employee6_.manager_id as manager_6_0_6_, employee6_.nnumber as nnumber5_0_6_ from nomination_nominees nominees0_ inner join nominee nominee1_ on nominees0_.nominees_id=nominee1_.id left outer join employee employee2_ on nominee1_.employee_id=employee2_.id left outer join employee employee3_ on employee2_.manager_id=employee3_.id left outer join nomination nomination4_ on nominee1_.nomination_id=nomination4_.id left outer join user user5_ on nomination4_.user_id=user5_.id left outer join employee employee6_ on user5_.employee_id=employee6_.id where nominees0_.nomination_id=?