질문&답변
spring boot버전...ㅠㅠ
@RestController @Data public class UserController {
- 좋아요수
- 0
- 댓글수
- 3
- 조회수
- 374
질문&답변
@RestController @Data public class UserController {
질문&답변
for 2.2 version 소스에서 UserController() 클레스에서 @Data 어노테이션으로 생성자를 써서 내부 클레스를 사용함. ( spring boot version ; 2.2.11 ) //User.java //@JsonFilter("UserInfo") public class User { private Integer id; @Size ( min = 2 , message = "Name 은 2 글자 이상 입력해주세요 ." ) private String name; @Past private Date joinDate; private String password; private String ssn; } //UserController.java // GET / users/1 or users/10 -- String @GetMapping ( "/users/{id}" ) public EntityModel User > retrieveUser ( @PathVariable int id ) { User user = service. findOne ( id ); if ( user == null ){ throw new UserNotFoundException ( String . format ( "ID[%s] not found " , id )); } // hateoas // "all-users", SERVER_PATH + "/users" // ret EntityModel User > model = new EntityModel (user); WebMvcLinkBuilder linkTo = linkTo ( methodOn ( this . getClass ()). retrieveAllUsers ()); model. add (linkTo. withRel ( "all-users" )); return model; } // 결과 { "id" : 1 , "name" : "Kenneth" , "joinDate" : "2020-11-26T10:40:55.183+0000" , "password" : "pass1" , "ssn" : "780702-1111111" , "links" : [ { "rel" : "all-users" , "href" : "http://localhost:8088/users" } ] }