xyz
xyz

Reputation: 2160

View logic in spring MVC

Spring MVC application with JPA

I have flow of my application like:

@Controller
Class 

---> returning a view (JSP) page.

Before returning to view I would like to modify contents or before sending it to entity persistence service layer , would like some values to be altered.Where shall I introduce those classes?

EDIT :

I am clear about rendering the data from database and displaying to front view. What I actually want to ask is like :

A a = aService.findXXX(aId);
//here i want some operations to be performed for specific view while converting it to dto and sending it to UI.

Where the class for doing the same would be introduced else my controller will have very large line of code sp. to what has to be displayed to sp. view?

Upvotes: 0

Views: 291

Answers (1)

Predrag Maric
Predrag Maric

Reputation: 24423

As @chrylis said, it's not very clear what you are asking. But if I understood you correctly, this will help you.

The usual pattern is that your @Controller has a @Autowired service reference

@Autowired
private MyService myService;

and that @Service has a @Autowired reference to DAO class (annotated with @Repository). Service encapsulates business logic, and DAO layer is responsible for interaction with database.

In your case, you would call some service method from controller, service would alter the entity and pass it down to DAO, and controller then fills the necessary data to Model which is used for rendering appropriate view.

Upvotes: 1

Related Questions