Reputation:
I am a very very beginner with Spring. And I need to understand how the following problem is soled in Spring.
Lets suppose I have a two pages - cars
and car
. On cars
page list of all cars is generated and user can apply different filters. On car
page user can read information about certain car. These are main parts of two pages.
However, both pages contain and two additional modules, lets say ads, and last user comments. Every module has its own logic and can use data from url/post/get. I mean
-------------------------
| ---------- |
| | Ads | |
| ---------- Car[s] |
| ---------- Page |
| | Comms | |
| ---------- |
-------------------------
So we see that in result we have two pages and some shared modules. Of course the code of these modules mustn't be duplicated for every page. How are such shared components are created in Spring? Please, give at least the name of the method/component, the rest I can read in internet.
Upvotes: 0
Views: 124
Reputation: 3453
From the backend side you can create request mapping for
@Path(/Cars) ModelAndView cars(...)
@Path(/Car) ModelAndView car(id)
@Path(/Ads) ModelAndView ads(...)
Each path will be connected with handler which could return ModelAndView
object. When you will send a request for /cars
you handler method will do some operations and also it can invoke method handler for each /car
- car(id)
and also ads()
.
ModelAndView cars(ids) {
doRequestSpecificOps()
result = new ModelAndView()
foreach id in ids
result put car(id)
result put ads()
return result
}
From the frontend side you should separate each representation block. It depends on your framework.
Upvotes: 1