×
☰ See All Chapters

DefaultAnnotationHandlerMapping

DefaultAnnotationHandlerMapping maps request to class and/or methods that are annotated with @RequestMapping annotation.

DefaultAnnotationHandlerMapping Example

package com.java4coding.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

@Controller

public class DemoController {

        @RequestMapping("pages/welcome.html")

        public ModelAndView helloWorld() {

                String message = "Welcome to Spring MVC Applications";

                return new ModelAndView("welcomepage", "welcomeMessage", message);

        }

}

 

<beans>

        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

               

        <context:component-scan base-package="com.java4coding.controller" />

 

        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix">

                        <value>/jsp/</value>

                </property>

                <property name="suffix">

                        <value>.jsp</value>

                </property>

       </bean>

<beans>

 

 


All Chapters
Author