Spring mvc--Adapter and Mapper (non-annotated)

Source: Internet
Author: User

<!--
Configuring a non-annotated processor adapter: Executing the processor according to the specified rules
-
<!--1. Simplecontrollerhandleradapter: Fits all processors that implement the Org.springframework.web.servlet.mvc.Controller interface--
<bean class= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" ></bean>

(Processor notation:

  

public class Hellocontroller implements Controller {

@Override
Public Modelandview HandleRequest (httpservletrequest request, httpservletresponse response) throws Exception {

Modelandview Mav = new Modelandview ();

Data, equivalent to Request.setattribute ();
Mav.addobject ("message", "Hello, controller Processor");

Specify return view
Mav.setviewname ("main.jsp");

return MAV;
}

}



<!--2. Httprequesthandleradapter: Compatible with all processors that implement the Org.springframework.web.HttpRequestHandler interface, which can coexist--
<bean class= "Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" ></bean>

(Processor notation:

  

public class HelloController2 implements Httprequesthandler {

@Override
public void HandleRequest (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {

Request.setattribute ("message", "Hello, controller processor _2....httprequesthandler");

Request.getrequestdispatcher ("/main.jsp"). Forward (request, response);

}

}



<!--
Configure a non-annotated processor mapper: Configure the mapping of the URL address to the processor
-
<!--1. Beannameurlhandlermapping: Matches the bean's Name property value according to the URL address--
<bean class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" ></bean>

<!--2. Simpleurlhandlermapping: Matches the bean's ID attribute value based on the URL address, which is an enhanced version of mode one, which can coexist--
<bean class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name= "Mappings" >
<props>
<prop key= "/hello11.action" >helloController</prop><!--key:url address Value:bean id attribute value--
<prop key= "/hello22.action" >helloController2</prop>
</props>
</property>
</bean>

Spring mvc--Adapter and Mapper (non-annotated)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.