teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

初心者マーク追加

2020/10/06 05:14

投稿

OG.
OG.

スコア7

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,6 @@
8
8
  検索機能を追加したい(とりあえず名前での検索のみ)
9
9
  簡易的でよいのでなんとか機能実装までに行きつきたいと考えております。
10
10
 
11
-
12
11
  ### 発生している問題・エラーメッセージ
13
12
 
14
13
  未入力の場合は一覧表示はできるようになったものの、検索する文字を入力した際の場合はリスト表示されず

1

list.htmlがうまく反映されてなかったため修正

2020/10/06 05:14

投稿

OG.
OG.

スコア7

title CHANGED
File without changes
body CHANGED
@@ -18,25 +18,6 @@
18
18
  お力を頂けますと幸いです。よろしくお願いします。
19
19
 
20
20
  ### 該当のソースコード
21
- AddressListApplication.java
22
- ```java
23
- package com.example.samplelist;
24
-
25
- import org.springframework.boot.SpringApplication;
26
- import org.springframework.boot.autoconfigure.SpringBootApplication;
27
-
28
- @SpringBootApplication
29
- public class AddressListApplication {
30
-
31
- public static void main(String[] args) {
32
- SpringApplication.run(AddressListApplication.class, args);
33
- }
34
-
35
- }
36
-
37
- ```
38
-
39
-
40
21
  DemoController.java
41
22
  ```ここに言語名を入力
42
23
  package com.example.samplelist;
@@ -191,47 +172,7 @@
191
172
  @Column
192
173
  private String area;
193
174
 
194
- public int getId() {
195
- return id;
196
- }
197
- public void setId(int id) {
198
- this.id = id;
199
- }
200
-
201
- public String getName() {
202
- return name;
203
- }
204
- public void setName(String name) {
205
- this.name = name;
206
- }
207
-
208
- public String getAddress() {
209
- return address;
210
- }
211
- public void setAddress(String address) {
212
- this.address = address;
213
- }
214
-
215
- public String getTel() {
216
- return tel;
217
- }
218
- public void setTel(String tel) {
175
+ //getter setter 部分省略
219
- this.tel = tel;
220
- }
221
-
222
- public String getZip() {
223
- return zip;
224
- }
225
- public void setZip(String zip) {
226
- this.zip = zip;
227
- }
228
-
229
- public String getArea() {
230
- return area;
231
- }
232
- public void setArea(String area) {
233
- this.area = area;
234
- }
235
176
  }
236
177
 
237
178
  ```
@@ -252,10 +193,8 @@
252
193
  package com.example.samplelist;
253
194
 
254
195
  import java.util.List;
255
-
256
196
  import org.springframework.beans.factory.annotation.Autowired;
257
197
  import org.springframework.stereotype.Service;
258
-
259
198
  @Service
260
199
  public class SearchService {
261
200
 
@@ -342,19 +281,65 @@
342
281
 
343
282
  list.html
344
283
  ```ここに言語名を入力
345
- package com.example.samplelist;
284
+ <!DOCTYPE html>
285
+ <html xmlns:th="http://www.thymeleaf.org">
286
+ <head>
287
+ <style>
288
+ //省略
346
289
 
290
+ </style>
291
+ </head>
292
+ <body>
293
+ <h1>住所録</h1>
294
+ <form class="form-group" action="/search" method="post" id="search">
295
+ <input class="form-control" type="text" name="name" id="name" th:value="${name}" size="30"
296
+ maxlength= "15" placeholder="search..." />
297
+ <input type="submit" class="btn btn-outline-secondary" value="検索"/>
298
+ </form>
299
+ <div id="tablearea">
300
+ <table border="1" class="table">
301
+ <thead class="thead-dark">
302
+ <tr>
303
+ <th scope="col" class="col_name">名前</th>
304
+ <th scope="col" class="col_zip">郵便番号</th>
305
+ <th scope="col" class="col_address">住所</th>
306
+ <th scope="col" class="col_tel">電話番号</th>
307
+ <th scope="col" class="col_area">地方</th>
308
+ <th class="col_edit"></th>
309
+ <th class="col_delete"></th>
310
+ </tr>
311
+ </thead>
312
+ <tr th:each=" obj:${lists}" th:object="${obj}">
313
+ <td th:text="*{name}"></td>
314
+ <td th:text="*{zip}"></td>
315
+ <td th:text="*{address}"></td>
316
+ <td th:text="*{tel}"></td>
317
+ <td th:text="*{area}"></td>
318
+ <td>
319
+ <form action="/edit" method="get">
320
+ <input type="submit" class="btn btn-outline-secondary" value="編集">
321
+ <input type="hidden" name="id" th:value="${obj.id}">
322
+ </form>
323
+ </td>
324
+ <td>
347
- import org.springframework.data.jpa.repository.JpaRepository;
325
+ <form action="/" method="post">
326
+ <input type="submit" class="btn btn-outline-danger" value="削除" onclick="return confirm('削除してもよろしいですか?')">
327
+ <input type="hidden" name="id" th:value="${obj.id}">
328
+ </form>
329
+ </td>
330
+ </tr>
331
+ </table>
332
+ </div>
333
+ <hr>
334
+ <form action="/add">
335
+ <input type="submit" id="add" class="btn btn-outline-secondary" value="新規追加" />
336
+ </form>
337
+ </body>
338
+ </html>
348
339
 
349
- public interface UserRepository extends JpaRepository<User, Long>{
350
- public User findById(int id);
351
- public void deleteById(int id);
352
- }
353
340
 
354
341
  ```
355
342
 
356
- ```
357
-
358
343
  ### 試したこと
359
344
 
360
345
  Spring 検索機能 等で検索エンジンに検索をかけ、ヒットしたサイトを手あたり次第参考にしました。