File tree 2 files changed +27
-1
lines changed
src/main/java/com/example/demo
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,13 @@ public class RestServiceJdbcImpl implements RestService {
23
23
// 1件登録用メソッド
24
24
@ Override
25
25
public boolean insert (User user ) {
26
- return false ;
26
+ int result = dao .insertOne (user );
27
+
28
+ if (result == 0 ) {
29
+ return false ;
30
+ } else {
31
+ return true ;
32
+ }
27
33
}
28
34
29
35
// 1件検索用メソッド
Original file line number Diff line number Diff line change 5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
6
import org .springframework .web .bind .annotation .GetMapping ;
7
7
import org .springframework .web .bind .annotation .PathVariable ;
8
+ import org .springframework .web .bind .annotation .PostMapping ;
9
+ import org .springframework .web .bind .annotation .RequestBody ;
8
10
import org .springframework .web .bind .annotation .RestController ;
9
11
10
12
import com .example .demo .domain .model .User ;
@@ -29,4 +31,22 @@ public User getUserOne(@PathVariable("id") String userId) {
29
31
// ユーザー1件取得
30
32
return service .selectOne (userId );
31
33
}
34
+
35
+ // ユーザー1件登録
36
+ @ PostMapping ("/rest/insert" )
37
+ public String postUserOne (@ RequestBody User user ) {
38
+ // ユーザーを1件登録
39
+ boolean result = service .insert (user );
40
+
41
+ String str = "" ;
42
+
43
+ if (result ) {
44
+ str = "{\" result\" :\" ok\" }" ;
45
+ } else {
46
+ str = "{\" result\" :\" error\" }" ;
47
+ }
48
+
49
+ // 結果用の文字列を返す
50
+ return str ;
51
+ }
32
52
}
You can’t perform that action at this time.
0 commit comments