29,700원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
EntityModel과 ResponseEntity의 차이
*UserController@GetMapping("/users/{id}") public EntityModel<User> retrieveUser(@Parameter(description = "사용자 ID", required = true, example = "1") @PathVariable int id) { User user = service.findOne(id); if (user == null) { throw new UserNotFoundException("id-" + id); } EntityModel entityModel = EntityModel.of(user); WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); entityModel.add(linkTo.withRel("all-users")); // http://127.0.0.1:8080/users try { return entityModel; } catch (Exception ex) { throw new RuntimeException(); } } @PostMapping("/users") public ResponseEntity<User> createUser(@Valid @RequestBody User user) { User savedUser = service.save(user); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{id}") .buildAndExpand(savedUser.getId()) .toUri(); return ResponseEntity.created(location).build(); } 두 클래스가 비슷하게 느껴져서 질문드립니다.EntityModel 클래스는 Spring HATEOAS에서 지원하는 클래스로 위의 코드로 특정 사용자 정보를 조회하면서 동시에 관련 리소스로 쉽게 이동할수 있는 링크를 제공을 도와주는 클래스고ResponseEntity클래스는 Spring MVC에서 지원하는 클래스로 HTTP 응답을 제어할 수 있도록 도와주며, 상태 코드, 헤더, 바디 등을 포함할수 있게 도와주는 클래스다. 라고 이해하면될까요 ?? 그렇기 때문에 Get에서는 해당 자원에 대한 추가적인 리소스를 제공하기 위해 EntityModel을 사용하고 Post에는 해당자원의 생성에 대한 201 상태코드를 제공하고 해당자원에 위치를 제공하기위해 ResponseEntity를 사용한것 인가요??Post에도 반환 값으로 EntityModel을 사용을 하는 경우도 있을까요??찾아보니 ResponseEntity<EntityModel<User>> 이렇게 사용하게 되는 경우 상태 코드와 함께 EntityModel<User>를 응답 본문으로 반환이 가능하다고 하는데 그렇다면 함께 사용하는 것이 데이터의 표현과 응답의 정확성을 높여줄것으로 예상이 되는데 이렇게 사용도 자주하는지 궁금합니다!
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
수업 그대로 따라했는데 404오류가 발생합니다.
안녕하세요 다국어 처리 수업 중에 수업 그대로 작성했는데 이러한 오류가 발생하게 됩니다.뭐 때문에 이러한 오류가 나는지 모르겠습니다..
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
DispatcherServlet과 프로젝트 동작의 이해
Port번호 변경이 안 됩니다. debug모드는 적용이 되는 것 같은데 왜그럴까요
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
optional관련 질문
안녕하세요 강의 너무 잘보고 있습니다.!단순 궁금증이 있어서요.optional로 조회하고와서 if (!userOptional.isPresent()) { throw new UserNotFoundException("id-" + id); }위와 같이 선언ㅇ하셧는데요 isEmpty를 사용하지 않고 위와 같이 하는 이유가 궁금합니다.
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
스웨거 query parameter 전달 방법
아무리 찾아도 나오질 않아서 여기에 글 남깁니다.스웨거 ui 에 파라미터 전달 방법에pageinteger($int64)(query) 이렇게 정의되어 있는건 이해가 되는데 cond[addr::LIKE]string($string)(query)이렇게 정의되어 있는건 query parameter를 어떤식으로 전달을 해야 하는가요?
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
강의 자료 ppt를 다운로드 받을 수 있을까요?
안녕하세요.이번에 개정판을 만들어 주셔서 감사합니다.다름이 아니라 강의 자료 ppt를 다운로드 받을 수 있을까요?커뮤니티 게시판을 보니 github에 https://github.com/joneconsulting/my-restful-services/tree/master/pdf 확인을 해보니 존재하지 않은 경로로 나오네요.
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
[Filter] Admin 에서 굳이 JsonFilter를 사용한이유
User api에서 ssn,paaword가 안보인 이유는 @JsonIgnoreProperties때문에 안보인 것 이고, AdminUser클래스에서는 @JsonIgnoreProperties를 제거 했기 때문에 굳이 SimpleFilterProvider를 사용할 필요는 없어 보입니다. 잘못된 사용 예로 보입니다..굳이 해당 예제 에서는 SimpleFilterProvider를 쓸필요는 없지만 이런식으로 필드 제어가 가능하다는 것 을 보여주시려고 이렇게 하시 건지 궁금합니다..\
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
Rest-API 작명
안녕하세요 현제 스터디 중인 대학생입니다. Rest-API 작명 때문에 궁금해서 질문을 남겼습니다.// 관리자 회원관리 GET /v1/admin/members// 전체 회원 조회 GET /v1/admin/members/1// 회원 상세 조회 PUT /v1/admin/members/1// 회원 수정 // 관리자 매장관리 GET /v1/admin/restaurants// 전체 매장 조회 GET /v1/admin/restaurants/1// 매장 상세 조회 POST /v1/admin/restaurants현제 이런 식으로 URL 정보를 미리 작성하고 규약을 따라 코드를 작성하는데, 궁금한 점이 GET /v1/admin/restaurants/search 이 방식과 GET /v1/restaurants/가게 이름 둘 중 어는 것이Rest API가 맞는지 궁금합니다.
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
spring security 문제
강의를 따라 pom.xml과 application.yml에 작성했던 spring security 관련 내용들을 주석 해제한 후 SecurityConfig.java에 webSecurityCustomizer()를 추가하고 실행했는데 사이트에 연결할 수 없다고 합니다. pom.xmlapplication.yml SecurityConfig.java사이트에 연결할 수 없음 상태가 지속되다가 어느 순간 console에 올라오는 에러 메시지는 다음과 같습니다.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService' defined in class path resource [kr/co/joneconsulting/myrestfulservice/config/SecurityConfig.class]: Failed to instantiate [org.springframework.security.core.userdetails.UserDetailsService]: Factory method 'userDetailsService' threw exception with message: null 강의와 동일하게 작성한 것 같은데 원인을 잘 모르겠습니다.
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
안드로이드 앱 서버개발 질문
안드로이드 앱 개발에서 백엔드를 맡아 서버를 개발해야 하는데요 강좌는 웹을 기반으로 rest api를 작성하는데 앱에 적용 시켜도 별반 차이가 없을까요?
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
MSA 강의는 언제쯤 업데이트 될까요?
이 강의와 연속성이 있는 강의라서 여쭤봐요!!
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
안녕하세요 사용자 전체 목록 보기 count, users 리스트를 반환하도록 하는 것에 대한 질문입니다.
response { "count": 5, "users": [ { "id": 90001, "name": "User1", "joinDate": "2024-02-04T07:40:02.160+00:00" }, { "id": 90002, "name": "User2", "joinDate": "2024-02-04T07:40:02.163+00:00" }, { "id": 90003, "name": "User3", "joinDate": "2024-02-04T07:40:02.163+00:00" }, { "id": 90004, "name": "User4", "joinDate": "2024-02-04T07:40:02.164+00:00" }, { "id": 90005, "name": "User5", "joinDate": "2024-02-04T07:40:02.164+00:00" } ]}hashmap 에 담아서 결과값을 반환해주는 식으로 했는데..상황에 따라 다르겠지만 의도하신 정답에 가까울까요..?
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
Intellij Database에서 테이블 조회
브라우저로 접속하였을 때는 테이블이 정상적으로 생성되는데인텔리제이 자체에서 확인하면 왜 테이블이 보이지 않는걸까요?새로고침해봐도 나타나지 않습니다
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
제 json은 왜 이렇게 나올까요?
(사진)
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
제 json은 왜 이렇게 나올까요?
(사진)
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
디폴트와 en이 작동하지 않습니다
다른 ko, ja, ch 는 모두 동작하지만Accept-Language를 설정하지 않거나Accept-Language를 en으로 설정하여도 계속안녕하세요 한글이 나오고 있습니다.무슨 문제일까요..? https://github.com/KMSKang/my-restful-service
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
Restful api 검색 조건 설계 시 uri 를 어떻게 해야 할까요?
안녕하세요 강사님. 강의 듣다가 Rest api 설계시 궁금한 점이 있어 여쭤봤습니다.rest api 설계 시 조회 부분에서 대부분 업무 로직이 사용자 조건 검색 같은게 많은데요 예를들어 사용자의 나이와 이름 등을 입력 받아 조회하는 등의 검색 조건을 나열해야 한다면 url 설계를 어떻게 해야 할까요?
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
강의 자료를 따로 제공하고 있나요?
PPT 자료를 제공하고 있다면 다운로드 받고 싶습니다.
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
Spring AOP를 이용한 Exception Handling
@ExceptionHandler(UserNotFoundException.class) public final ResponseEntity<Object> handleUserNotFoundException(Exception ex, WebRequest request) { ExceptionResponse exceptionResponse = new ExceptionResponse(new Date(), ex.getMessage(), request.getDescription(false)); return new ResponseEntity<>(exceptionResponse, HttpStatus.NOT_FOUND); } 강의에서 WebRequest를 이용하여 exception handling을 하고 있는데, 아래처럼 BindingResult를 사용하는 방법과 어떤 부분이 다른가요? 개발 스타일에 따라 사용하면 될까요? @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { List<String> errorMessages = e.getBindingResult().getFieldErrors() .stream() .map(FieldError::getDefaultMessage) .collect(Collectors.toList()); String combinedErrorMessage = String.join(", ", errorMessages); return ResponseEntity.badRequest().body(new ErrorResponse(combinedErrorMessage)); }
- 미해결[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발
create posts 부분에서의 에러 발생
https://www.inflearn.com/course/lecture?courseSlug=spring-boot-restful-web-services&unitId=39127&tab=community&category=questionDetail&q=222413해당 강의에서의 posts create 부분에 500 interna error가 발생해서 문의드립니다 package com.example.restfulwebservice.bean; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import javax.persistence.*; @Entity @Data @NoArgsConstructor @AllArgsConstructor public class Post { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String description; // 게시물:사용자는 N:1 관계 // JsonIgnore 통해서 정보를 가져오지 않음 @ManyToOne(fetch = FetchType.LAZY) // FetchType.LAZY는 지연 로딩, 사용자 데이터를 필요한 시점에 가져옴. 즉시 로딩 안함 @JsonIgnore // 다른 엄한 JsonIgnore를 불러오는 바람에 N+1 문제가 너무 크게 발생함.... private User user; } Post.java package com.example.restfulwebservice.Controller; import com.example.restfulwebservice.bean.Post; import com.example.restfulwebservice.bean.User; import com.example.restfulwebservice.exception.UserNotFoundException; import com.example.restfulwebservice.exception.UsersAndCountResponse; import com.example.restfulwebservice.repository.PostRepository; import com.example.restfulwebservice.repository.UserRepository; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import javax.validation.Valid; import java.net.URI; import java.util.Date; import java.util.List; import java.util.Optional; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; @RestController @RequestMapping("/jpa") public class UserJPAController { private UserRepository userRepository; private PostRepository postRepository; public UserJPAController(UserRepository userRepository){ this.userRepository = userRepository; } // /jpa/users @GetMapping("/users") public List<User> retrieveAllUsers(){ return userRepository.findAll(); } // ResponseEntity를 사옹한 정답 코드 @GetMapping("/usersAndCount") public ResponseEntity retrieveAllUsersAndCount(){ List<User> users = userRepository.findAll(); int count = users.size(); UsersAndCountResponse result = UsersAndCountResponse.builder() .count(users.isEmpty() ? 0 : users.size()) .users(users) .build(); EntityModel entityModel = EntityModel.of(result); WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); entityModel.add(linkTo.withSelfRel()); return ResponseEntity.ok(entityModel); } // jpa/users/{id} @GetMapping("/users/{id}") public ResponseEntity retrieveUsersById(@PathVariable int id){ Optional<User> user = userRepository.findById(id); if (!user.isPresent()){ throw new UserNotFoundException("id - " + id); } EntityModel entityModel = EntityModel.of(user.get()); WebMvcLinkBuilder lintTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); entityModel.add(lintTo.withRel("all-users")); return ResponseEntity.ok(entityModel); } @DeleteMapping("/users/{id}") public void deleteUser(@PathVariable int id){ userRepository.deleteById(id); } // /jpa/users @PostMapping("/users") public ResponseEntity<User> createUser(@Valid @RequestBody User user){ if(user.getJoinDate() == null) user.setJoinDate(new Date()); User savedUser = userRepository.save(user); // USER CREATED // /users/4 // 생성된 User의 URI를 저장 후 반환하기 URI location = ServletUriComponentsBuilder .fromCurrentRequest() .path("/{id}") .buildAndExpand(savedUser.getId()) .toUri(); return ResponseEntity.created(location).build(); } @GetMapping("/users/{id}/posts") public List<Post> retrieveAllPostByUser(@PathVariable int id){ Optional<User> user = userRepository.findById(id); if(!user.isPresent()){ throw new UserNotFoundException("id-" + id + " user not found"); } return user.get().getPosts(); } @PostMapping("/users/{id}/posts") public ResponseEntity<Post> createPost(@PathVariable int id, @RequestBody Post post) { Optional<User> userOptional = userRepository.findById(id); if (!userOptional.isPresent()) { throw new UserNotFoundException("id-" + id); } User user = userOptional.get(); post.setUser(user); postRepository.save(post); URI location = ServletUriComponentsBuilder .fromCurrentRequest() .path("/{id}") .buildAndExpand(post.getId()) .toUri(); return ResponseEntity.created(location).build(); } } UserJPAController.java 파일이고, user의 post 통한 생성과 get 통한 id로 해당 사용자 post 조회는 이상 없습니다