CuriousMind
CuriousMind

Reputation: 8903

Organising View in Spring MVC in real enterprise based application?

I am learning Spring MVC framework, and created a simple "Hello world" kind of web-application using Spring MVC framework.

My controller code is like this:

@Controller
public class SimpleController {

    @RequestMapping("/welcome")
    ModelAndView handleIncomingWelcomeReq() {

        ModelAndView mw = new ModelAndView("WelcomePage","welcomeKey","WelcomeKey's value!");
        return mw;
    }
}

The spring configuration is:

<beans>
    <context:component-scan base-package="com.example.controller, com.example.util"/>
    <bean id="viewResolver1" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix"> <value>/WEB-INF/</value> </property>
        <property name="suffix"> <value>.jsp</value> </property>
    </bean>
</beans>

The code is straightforward, for /welcome , handleIncomingWelcomeReq() gets invoked and welcomePage.jsp is returned to the client.

For this simple application, we need to specifically mention the view page which it returns. Now my question is:

  1. In real enterprise web-applications, how do we organise the view / page which gets returned for matching url. Wouldn't the spring configuration get too big, because we have to specifically mention the page which gets returned for each incoming url.

  2. Is this the way Spring MVC builds the real life enterprise web application. Each page specifically mentioned in the spring configuration page?

Any inputs on this which help clarify this really appreciated.

Upvotes: 0

Views: 41

Answers (1)

AchillesVan
AchillesVan

Reputation: 4356

The responsibility of defining the page flow specifically lies on individual controllers and views; for instance, you usually map a web request to a controller, and the controller is the one that decides which logical view needs to be returned as a response. This is sufficient for straightforward page flows, but when your application gets more and more complex (real enterprise web-applications) in terms of user interface flows, maintainance becomes a nightmare. If you are going to develop such a complex flow-based application, then Spring Web Flow can be a good companion. Spring Web Flow allows you to define and execute user interface flows within your web application.

Upvotes: 1

Related Questions