###前提・実現したいこと
thymeleafでDBに登録されているユーザー情報一覧を取得し テーブル上に表示する機能を作っています。 ユーザーIDやメールアドレスなどは <td th:text="${user.username}">taro.yamada@gmail.com</td> を使って取得したものをそのまま表示しているのですが、 権限に関しては取得したものが 一般ユーザーだと[ROLE_USER] 管理者だと[ROLE_ADMIN, ROLE_USER] になってしまうので、 ここをうまく一般ユーザー、管理者と表示できるようにしたいです!
###該当のソースコード
html
1 <div class="container"> 2 <hr /> 3 <table class="table table-striped table-bordered table-condensed"> 4 <tr> 5 <th>ID</th> 6 <th>姓</th> 7 <th>名</th> 8 <th>メールアドレス</th> 9 <th>権限</th> 10 <th colspan="2">編集</th> 11 </tr> 12 <tr th:each="user : ${userList}"> 13 <td th:text="${user.id}">1</td> 14 <td th:text="${user.lastName}">山田</td> 15 <td th:text="${user.firstName}">太郎</td> 16 <td th:text="${user.username}">taro.yamada@gmail.com</td> 17 <td th:text="${user.authorities}">一般ユーザー</td> 18 <td> 19 <form th:action="@{/user/update/input}" method="GET"> 20 <input class="btn btn-info" type="submit" name="updateUser" value="編集" /> 21 <input type="hidden" name="id" th:value="${user.id}" /> 22 </form> 23 </td> 24 <td> 25 <form th:action="@{/user/delete/confirm}" method="POST"> 26 <input class="btn btn-danger" type="submit" name="deleteUser" value="削除" /> 27 <input type="hidden" name="id" th:value="${user.id}" /> 28 </form> 29 </td> 30 </tr> 31 </table> 32 </div>
java
1 @GetMapping("/userlist") 2 public String userList(Model model) { 3 Iterable<User> userList = userRepository.findAll() ; 4 model.addAttribute("userList", userList) ; 5 return "/user/list"; 6 }
###補足情報(言語/FW/ツール等のバージョンなど)
eclipse, spring, thymeleaf
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/17 09:05