스프링

 

 

 

 

 

    // GET  /admin/users/1 -> /admin/v1/users/1
   // @GetMapping("/v1/users/{id}")
 //   @GetMapping(value="/users/{id}", params="version=1" )
    //@GetMapping(value = "/users/{id}", headers = "X-API-TEST-VERSION=1")
    @GetMapping(value = "/users/{id}", produces = "application/vnd.myTest.appv1+json")
    public MappingJacksonValue retrieveUserV1(@PathVariable int id){
        User user =service.findOne(id);
        if(user==null){
            throw new UserNotFoundException(String.format("ID[%s] not found", id));
        }

        SimpleBeanPropertyFilter filter =SimpleBeanPropertyFilter.filterOutAllExcept("id","name", "joinDate", "ssn");
        FilterProvider filters =new SimpleFilterProvider().addFilter("UserInfo", filter);

        MappingJacksonValue mapping =new MappingJacksonValue(user);
        mapping.setFilters(filters);
        return mapping;
    }




    // GET  /admin/users/1 -> /admin/v2/users/1
  //  @GetMapping("/v2/users/{id}")

//    @GetMapping(value = "/users/{id}", params = "version=2")
    //@GetMapping(value = "/users/{id}", headers = "X-API-TEST-VERSION=2")
    @GetMapping(value = "/users/{id}" , produces = "application/vnd.myTest.appv2+json")
    public MappingJacksonValue retrieveUserV2(@PathVariable int id){
        System.out.println("MappingJacksonValue  V2=========================> ");
        User user =service.findOne(id);
        if(user==null){
            throw new UserNotFoundException(String.format("ID[%s] not found", id));
        }

        //User -> User2
        UserV2 userV2=new UserV2();
        BeanUtils.copyProperties(user, userV2); //id, name, joinDate, password, ssn
        userV2.setGrade("VIP");

        SimpleBeanPropertyFilter filter =SimpleBeanPropertyFilter.filterOutAllExcept("id", "name", "joinDate", "grade");
        FilterProvider filters =new SimpleFilterProvider().addFilter("UserInfo2", filter);

        MappingJacksonValue mapping =new MappingJacksonValue(userV2);
        mapping.setFilters(filters);
        return mapping;
    }

 

 

 

 

 

 

spring

 

about author

PHRASE

Level 60  라이트

욕심이 잉태하면 죄를 낳고, 그것이 자라 장성하면 죽음에 이르니라.

댓글 ( 4)

댓글 남기기

작성