소스 검색

made some changes in my controller

Roy 6 년 전
부모
커밋
2c788f0e35
1개의 변경된 파일7개의 추가작업 그리고 5개의 파일을 삭제
  1. 7
    5
      server/src/main/java/com/example/demo/user/UserController.java

+ 7
- 5
server/src/main/java/com/example/demo/user/UserController.java 파일 보기

@@ -1,6 +1,8 @@
1 1
 package com.example.demo.user;
2 2
 
3
+import com.fasterxml.jackson.databind.ObjectMapper;
3 4
 import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.http.ResponseEntity;
4 6
 import org.springframework.stereotype.Controller;
5 7
 import org.springframework.web.bind.annotation.*;
6 8
 
@@ -11,14 +13,14 @@ public class UserController {
11 13
 
12 14
     @Autowired // this means to get bean called userRepository which is auto-generated by spring. it is ued to handle data
13 15
     private UserRepository userRepository;
14
-
16
+        ObjectMapper om = new ObjectMapper();
15 17
 
16 18
     @PostMapping(path="/add")
17
-    public @ResponseBody String addNewUser(@RequestParam String username, @RequestParam String email, @RequestParam String password){ //ResponseBody means the returned string is the response
19
+    //public @ResponseBody String addNewUser(@RequestParam String username, @RequestParam String email, @RequestParam String password){ //ResponseBody means the returned string is the response
18 20
         //RequestParam means it is a parameter from a GET or POST request
19
-        User n = new User(username, email, password);
20
-        userRepository.save(n);
21
-        return "Saved";
21
+      public @ResponseBody String addNewuser(@RequestBody User user) {
22
+        userRepository.save(user);
23
+        return "saved";
22 24
     }
23 25
 
24 26
     @GetMapping(path="/all")