SPRINGMVC (iii) configuration of processor Mapper and use of Abstractcontroller

Source: Internet
Author: User

At the beginning of the creation of the SPINGMVC project, we only need to configure the front controller and the processor, the other three systems will be configured by default, we can also configure

First look at configuring the processor mapper, the system default

Configuring in Springmvc.xml

Another way to configure this is to configure the same in Springmvc.xml, using the Simpleurlhandlermapping class

<beanclass="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> &lt;! &ndash; Mode One &ndash;&gt; <property name="Mappings"> <props> <prop key="/hello">firstController</prop> </props> </property>Mode two<property name="UrlMap"> <map> <entry key="/hello"Value="Firstcontroller"></entry> </map> </property> </bean>

When this configuration is accessed, the value of the key can be accessed directly.

Two. About Abstractcontroller

Define a class that allows him to inherit Abstractcontroller

Package Demo03abstractcontroller;import Org.springframework.web.servlet.modelandview;import Org.springframework.web.servlet.mvc.abstractcontroller;import Org.springframework.web.servlet.mvc.Controller; Import Javax.servlet.http.httpservletrequest;import javax.servlet.http.HttpServletResponse;/** * Created by mycom on 2018/3/18.*/ Public classFirstcontroller extends Abstractcontroller {protectedModelandview handlerequestinternal (httpservletrequest httpservletrequest, HttpServletResponse HttpServletResponse) throws Exception {Modelandview mv=NewModelandview (); Mv.setviewname ("Index"); returnMV; }}

In the configuration file Springmvc.xml

<!--registered Processor--    <beanid= "/firstcontroller"class="  Demo03abstractcontroller.firstcontroller" >        <property name="  Supportedmethods "value="post,get"></property>    </bean>

SPRINGMVC (iii) configuration of processor Mapper and use of Abstractcontroller

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.