質問編集履歴
1
実際のサーブレット側のコードを追記します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,7 +94,49 @@
|
|
94
94
|
|
95
95
|
サーブレットで
|
96
96
|
|
97
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
98
|
+
|
99
|
+
EntityManager em = DBUtil.createEntityManager();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
int page = 1;
|
108
|
+
|
109
|
+
try{
|
110
|
+
|
111
|
+
page = Integer.parseInt(request.getParameter("page"));
|
112
|
+
|
113
|
+
} catch(NumberFormatException e) { }
|
114
|
+
|
115
|
+
List<Employee> employees = em.createNamedQuery("getAllEmployees", Employee.class)
|
116
|
+
|
117
|
+
.setFirstResult(15 * (page - 1))
|
118
|
+
|
119
|
+
.setMaxResults(15)
|
120
|
+
|
121
|
+
.getResultList();
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
long employees_count = (long)em.createNamedQuery("getEmployeesCount", Long.class)
|
126
|
+
|
127
|
+
.getSingleResult();
|
128
|
+
|
129
|
+
//現在ログインしているユーザーのID
|
130
|
+
|
131
|
+
Integer id;
|
132
|
+
|
133
|
+
Employee login_employee = (Employee)request.getSession().getAttribute("login_employee");
|
134
|
+
|
135
|
+
id=login_employee.getId();
|
136
|
+
|
137
|
+
//現在ログインしているユーザーのIDをもとにフォローリストテーブルデータを取得
|
138
|
+
|
97
|
-
List<Employee> follow_list =em.createNamedQuery("getMyfollowlist", Employee.class)
|
139
|
+
List<Employee> follow_list =em.createNamedQuery("getMyfollowlist", Employee.class)
|
98
140
|
|
99
141
|
.setParameter("id",id)
|
100
142
|
|
@@ -102,6 +144,60 @@
|
|
102
144
|
|
103
145
|
|
104
146
|
|
147
|
+
em.close();
|
148
|
+
|
149
|
+
//現在ログインしているユーザーが、employeesで取得した格社員をフォローしているかしていないかをMapで管理
|
150
|
+
|
151
|
+
Map<Integer,Boolean> map = new HashMap<>();
|
152
|
+
|
153
|
+
employees.forEach(employee -> {
|
154
|
+
|
155
|
+
if(follow_list.contains(employee.getId())){
|
156
|
+
|
157
|
+
map.put(employee.getId(), true);
|
158
|
+
|
159
|
+
}else {
|
160
|
+
|
161
|
+
map.put(employee.getId(), false);
|
162
|
+
|
163
|
+
};
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
request.setAttribute("employees", employees);
|
174
|
+
|
175
|
+
request.setAttribute("employees_count", employees_count);
|
176
|
+
|
177
|
+
request.setAttribute("page", page);
|
178
|
+
|
179
|
+
request.setAttribute("map", map);
|
180
|
+
|
181
|
+
if(request.getSession().getAttribute("flush") != null) {
|
182
|
+
|
183
|
+
request.setAttribute("flush", request.getSession().getAttribute("flush"));
|
184
|
+
|
185
|
+
request.getSession().removeAttribute("flush");
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/followlist/index.jsp");
|
192
|
+
|
193
|
+
rd.forward(request, response);
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
105
201
|
のようにフォローした社員情報をList型で取得したいのですが
|
106
202
|
|
107
203
|
Parameter value [1] did not match expected type [models.Employee (n/a)]
|