Propertiesmethodnameresolver Property Method Name Resolver in SSM-SPRINGMVC-10:SPRINGMVC

Source: Internet
Author: User

------------I do not have him, but the hand is ripe, humble and foolish, and eager to be hungry-------------

The last inherited Multiactioncontroller can implement multiple processing methods in a processor, but it is limited, their URL access address can only be the same as the method name, because his default method name resolver is Internalpathmethodnameresolver

If we want to consider the security of the program or even more (from the URL concise Ah, the same name Ah, etc.) so introduced a called Propertiesmethodnameresolver attribute method name Parser this thing

Let me say something. Use the steps used on the previous case basis

1. Write a bean definition in the configuration file this Propertiesmethodnameresolver This property method name resolver

2. In the bean of the custom inheriting Multiactioncontroller class, inject the above step one configuration of that method name resolver

Specific use, I give two pieces of code is enough

Inherit the Multiactioncontoller class, my class name and source code are below

Package Cn.dawn.day05multiactioncontroller;import Org.springframework.web.servlet.modelandview;import Org.springframework.web.servlet.mvc.multiaction.multiactioncontroller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.HttpServletResponse;/** * Created by Dawn on 2018/3/23.*/ Public classMymultiactioncontroller extends multiactioncontroller{ PublicString Dofirst (httpservletrequest httpservletrequest, HttpServletResponse httpservletresponse) throws Exception { Modelandview Me=NewModelandview (); Me.setviewname (" First"); return " First"; }     PublicModelandview Dosecond (httpservletrequest httpservletrequest, HttpServletResponse HttpServletResponse) throws Exception {Modelandview me=NewModelandview (); Me.setviewname ("Second"); returnme; }}

  

In my own XML configuration file, two steps, I marked out

<?xml version="1.0"encoding="UTF-8"? ><beans xmlns="Http://www.springframework.org/schema/beans"Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"Xmlns:mvc="Http://www.springframework.org/schema/mvc"xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--Configuring Bean processors--<bean id="Mymultiactioncontroller" class="Cn.dawn.day05multiActioncontroller.MyMultiActionController"><!--The second step ========= injection method name Resolver --<property name="Methodnameresolver" ref="Propertiesmethodnameresolver"></property> </bean> <!--view Resolver-<beanclass="Org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"Value="/"></property> <property name="suffix"Value=". JSP"></property> </bean><!--First Step ======= Property method name Resolver --<bean id="Propertiesmethodnameresolver" class="Org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="Mappings"> <props> <prop key="/doone">doFirst</prop> <prop key="/dotwo">doSecond</prop> </props> </property> </bean> <beanclass="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <!--the first way--<property name="UrlMap"> <map> <!--here to change/*, not the kind that was written dead before-- <entry key= "/*" > <value>mymultiactioncontroller< ;/value> </entry> </map> </property> </bean></beans>< /c3>

Then the URL address of your Web page is the value of that key there,

It is important to note that first.jsp and second.jsp are you ready?

Web. XML configuration file you pointed to changed it?

Propertiesmethodnameresolver Property Method Name Resolver in SSM-SPRINGMVC-10:SPRINGMVC

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.