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
27 changes: 27 additions & 0 deletions src/main/java/com/example/springhw1/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
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.web.bind.annotation.*;

@RestController
public class UserController {
private final UserService userService;

@Autowired
public UserController(UserService userService) {
this.userService = userService;
}

@PostMapping("/users/join")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

아 requestparam으로 하는 방법도 있군요! 전 그냥 하드 코딩했는데...

public User signIn(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("nickname") String nickname) {
return userService.saveUser(username, password, nickname);
}

@GetMapping("/users/id/{id}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

username으로 찾는건데 id로 찾은 이유가 궁금합니다

public User getUserById(@PathVariable("id") Long id) {
return userService.findUserById(id);
}

@GetMapping("/users/username/{username}")
public User getUserByUsername(@PathVariable("username") String username) {
return userService.findUserByUsername(username);
}
}
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/{ your_database_name }?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
username: { your_username }
password: { your_password }
url: jdbc:mysql://localhost:3306/spring_study?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
username: root
password: kimna04!
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
Expand Down