File tree 2 files changed +51
-2
lines changed
src/main/java/com/example/demo
2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,24 @@ public List<User> selectMany() {
47
47
// 1件更新用メソッド
48
48
@ Override
49
49
public boolean update (User user ) {
50
- return false ;
50
+ int result = dao .updateOne (user );
51
+
52
+ if (result == 0 ) {
53
+ return false ;
54
+ } else {
55
+ return true ;
56
+ }
51
57
}
52
58
53
59
// 1件削除用メソッド
54
60
@ Override
55
61
public boolean delete (String userId ) {
56
- return false ;
62
+ int result = dao .deleteOne (userId );
63
+
64
+ if (result == 0 ) {
65
+ return false ;
66
+ } else {
67
+ return true ;
68
+ }
57
69
}
58
70
}
Original file line number Diff line number Diff line change 3
3
import java .util .List ;
4
4
5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .web .bind .annotation .DeleteMapping ;
6
7
import org .springframework .web .bind .annotation .GetMapping ;
7
8
import org .springframework .web .bind .annotation .PathVariable ;
8
9
import org .springframework .web .bind .annotation .PostMapping ;
10
+ import org .springframework .web .bind .annotation .PutMapping ;
9
11
import org .springframework .web .bind .annotation .RequestBody ;
10
12
import org .springframework .web .bind .annotation .RestController ;
11
13
@@ -49,4 +51,39 @@ public String postUserOne(@RequestBody User user) {
49
51
// 結果用の文字列を返す
50
52
return str ;
51
53
}
54
+
55
+ // ユーザー1件更新
56
+ @ PutMapping ("/rest/update" )
57
+ public String putUserOne (@ RequestBody User user ) {
58
+ // ユーザー1件更新
59
+ boolean result = service .update (user );
60
+
61
+ String str = "" ;
62
+
63
+ if (result ) {
64
+ str = "{\" result\" :\" ok\" }" ;
65
+ } else {
66
+ str = "{\" result\" :\" error\" }" ;
67
+ }
68
+
69
+ return str ;
70
+ }
71
+
72
+ // ユーザー1件削除
73
+ @ DeleteMapping ("/rest/delete/{id:.+}" )
74
+ public String deleteUserOne (@ PathVariable ("id" ) String userId ) {
75
+ // ユーザー1件削除
76
+ boolean result = service .delete (userId );
77
+
78
+ String str = "" ;
79
+
80
+ if (result ) {
81
+ str = "{\" result\" :\" ok\" }" ;
82
+ } else {
83
+ str = "{\" result\" :\" error\" }" ;
84
+ }
85
+
86
+ // 結果用の文字列をリターン
87
+ return str ;
88
+ }
52
89
}
You can’t perform that action at this time.
0 commit comments