0

I have an entity in my application that have a composed ID.
In my controller I get this entity using the @PathVariable in this way:

@RequestMapping("/{year}/{code}")
public MyCustomObj get(@PathVariable Integer year, @PathVariable Integer code){
    return myCustomObjRepository.findOne(new CustomId(year, code));
}

Is it possible, using some component like WebArgumentResolver, to make my method works in this way:

@RequestMapping("/{customObj}")
public MyCustomObj get(@PathVariable CustomId id){
    return myCustomObjRepository.findOne(id);
}

having a the URL like: /application/2013/06

rascio
  • 8,968
  • 19
  • 68
  • 108

1 Answers1

0

You can do this by registering a custom filter and overriding the doFilterMethod as shown below.

 public void doFilter(ServletRequest arg0, ServletResponse arg1,
        FilterChain chain){
 HttpServletRequest request = (HttpServletRequest) arg0;
 HttpServletResponse response = (HttpServletResponse) arg1;
 String args = request.getRequestURI();
 //get your year and code
 MyCustomObj obj = new CustomId(year, code);
 response.sendRedirect("someURL/obj");
 }
shazinltc
  • 3,616
  • 7
  • 34
  • 49