user5182503
user5182503

Reputation:

How to create modules in spring

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

Answers (1)

Sergei Rybalkin
Sergei Rybalkin

Reputation: 3453

From the backend side you can create request mapping for

  1. @Path(/Cars) ModelAndView cars(...)
  2. @Path(/Car) ModelAndView car(id)
  3. @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

Related Questions