• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Avoid repetitive code in controllers - Spring MVC

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

I have the below requirement..

On each controller, immediately after the POST method is initiated I need to take the two attributes from the model and pass it to business layer.

I disregarded the following approaches

1. Either calling the business service in each controller or writing a utility class and auto wire it to controller and calling the method these process may reduce the repetitive code, but it is not effective.

2. Interceptors, are not helpful, because, I need to inject the model attributes immediately after POST method started executed.

Is there any best way to do this, without repetitive code

Thanks in advance,

Thanks,
Suresh.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Spring AOP @Before advice.
Use getArgs() of JoinPoint to do what you want to do with those arguments of the method.
You can find many examples online. See and let us know if it worked.
 
kalle suresh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. Thank you. I will give a try.

Thanks,
Suresh.
 
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic