Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ out/

### VS Code ###
.vscode/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

악 이거 넣는거 까먹었다 감사합니다~

# Ignore all YAML files
*.yaml
*.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
package com.example.springhw1.controller;


import com.example.springhw1.entity.User;
import com.example.springhw1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController //HTTP 요청, JSON 반환
@RequestMapping("/users")//이 클래스의 모든 메서드 /users 경로 사용
public class UserController {
}

private final UserService userService;

@Autowired//의존성 주입
public UserController(UserService userService) {
this.userService = userService;
}

@PostMapping("/join")//데이터 전송하거나 생성할 때
public User 회원가입(
@RequestParam String username,
@RequestParam String password,
@RequestParam String nickname) {
Comment on lines +23 to +25
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!
생략해도 무관한 부분이라 굳이 수정 안해도 괜찮아~
@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("nickname") String nickname

생략된 부분이 있다는 거 꼭 알고 쓰면 됩니다~


User savedUser = userService.saveUser(username, password, nickname);
return savedUser;
Comment on lines +27 to +28
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거는 수정할 부분은 아니고 참고하면 좋은 부분이라 comment 남겨요
UserService의 saveUser라는 메서드 리턴값을 보면 User를 리턴하죠?
그래서 27, 28번 째 줄을 하나로 합칠 수 있어요
savedUser라는 변수를 할당해서 지금처럼 리턴해도 되고
코드를 한줄이라도 줄이고 싶다면
return userService.saveUser(username, password, nickname); 이런식으로 줄이는 것도 가능합니다

물론 이거는 본인 코딩 스타일이라 굳이 어떤 방법이 좋다 이건 없어

}

@GetMapping("/id/{id}")//데이터 조회할 때
public User getUserById(@PathVariable Long id){//변수 값 추출
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 마찬가지
생략된 부분이 있다는 것만 알고 공부하면 돼~
수정 안해도 괜찮아
@PathVariable("id") Long id

return userService.findUserById(id);
}

@GetMapping("/username/{username}")
public User getUserByUsername(@PathVariable String username){
return userService.findUserByUsername(username);
}
//dfsdfdf
}
15 changes: 0 additions & 15 deletions src/main/resources/application.yml

This file was deleted.