无法在百里香页中与用户打印关联角色

问题描述

我是春季靴的新手,有人可以帮忙吗!

我有一个显示设置页面的控制器。

@GetMapping("/setting")
public String settings(Model model){
    List<User> user =  userDao.findAll();
    model.addAttribute("user",user);
    return "settings";
}

我的查询

 @Query(value = "SELECT * FROM users u left join user_role ur on u.id = ur.user_id",nativeQuery=true)

 List<User> findAll();

在渲染时,设置页面如下所示。

enter image description here

我需要显示用户角色,例如(管理员/主持人等)以及角色ID

具有角色的用户的映射是多对多的。

    @ManyToMany(cascade=CascadeType.MERGE)
    @JoinTable(
          name="user_role",joinColumns={@JoinColumn(name="USER_ID",referencedColumnName="ID")},inverseJoinColumns={@JoinColumn(name="ROLE_ID",referencedColumnName="ID")})
    private List<Role> roles;

在设置页面中,我无法获得角色的值。

           <tbody>
                <tr th:each="u,iterator : ${user}">
                    <!-- <td th:text="${u.id}"></td> -->
                    <td th:text="${iterator.index+1}"></td>
                    <td th:text="${u.name}"></td>  
                     <td th:if="${u.isActive}"><span class="status text-success">&bull;</span> Active</td>
                    <td th:unless="${u.isActive}"><span class="status text-warning">&bull;</span> InActive</td>                     
                    <td>****need to get role here***</td>
                </tr>
           </tbody>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)