SSM-SpringMVC-10:SpringMVC中PropertiesMethodNameResolver属性方法名称解析器
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
上次的以继承MultiActionController可以实现一个处理器中多个处理方法,但是局限出来了,他们的url访问地址只能是与方法名称相同的,因为他默认的方法名称解析器是InternalPathMethodNameResolver
如果我们想为了程序的安全甚至更多考虑(从url简洁啊,同名啊,等等)所以引入了一个叫PropertiesMethodNameResolver属性方法名称解析器的这个东西
我说一下使用在上一个案例基础上使用的步骤
1.在配置文件中写一个bean定义这个PropertiesMethodNameResolver这个属性方法名称解析器
2.在自定义的继承MultiActionController的类的bean中注入上面的步骤一配置的那个方法名称解析器
具体使用,我给俩段代码就够了
继承MultiActionContoller的类,我的类名和源码在下面
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 class MyMultiActionController extends MultiActionController{ public String doFirst(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView me=new ModelAndView();
me.setViewName("first");
return "first";
} public ModelAndView doSecond(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView me=new ModelAndView();
me.setViewName("second");
return me;
}
}
在自己的xml配置文件中,俩步骤,我标出来
<?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"> <!--配置bean处理器-->
<bean id="myMultiActionController" class="cn.dawn.day05multiActioncontroller.MyMultiActionController">
<!--第二步=========注入方法名称解析器-->
<property name="methodNameResolver" ref="propertiesMethodNameResolver"></property>
</bean>
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean> <!--第一步=======属性方法名称解析器-->
<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> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<!--第一种方式-->
<property name="urlMap">
<map>
<!--这儿需要改成/*,而不是之前写死的那种-->
<entry key="/*">
<value>myMultiActionController</value>
</entry>
</map>
</property>
</bean> </beans>
然后你网页访问的url地址就是那里那个key的值,
此处需要注意的是first.jsp和second.jsp你准备了吗?
web.xml你指向的xml配置文件改了吗?
SSM-SpringMVC-10:SpringMVC中PropertiesMethodNameResolver属性方法名称解析器的更多相关文章
- spring mvc: 属性方法名称解析器(多动作控制器)MultiActionController/ControllerClassNameHandlerMapping/PropertiesMethodNameResolver
spring mvc: 属性方法名称解析器(多动作控制器) 加入控制器是StudentContrller.java,里面有3个方法 index,add,remove 那么访问地址是: http://l ...
- Spring MVC属性方法名称解析器
以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的属性方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...
- SSM-SpringMVC-11:SpringMVC中ParameterMethodNameResolver参数方法名称解析器
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 或许曾经的我们也见过一种方式http://localhost:8080/项目名/后台servlet?actio ...
- Spring MVC-控制器(Controller)-属性方法名称解析器(Properties Method Name Resolver )示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_propertiesmethodnameresolver.htm 说明:示例基于S ...
- SpringMVC处理器映射器和方法名称解析器
所谓配置式开发是指,“处理器类是程序员手工定义的,实现了特定接口的类,然后再在SpringMVC配置文件中对该类进行显式的,明确的注册”的开发方式” 1.处理器映射器HandlerMapping Ha ...
- spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClassNameHandlerMapping
spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClas ...
- Spring MVC参数方法名称解析器
以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的参数方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...
- Spring MVC-控制器(Controller)-参数方法名称解析器(Parameter Method Name Resolver )示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_parametermethodnameresolver.htm 说明:示例基于Sp ...
- SpringMVC03 ParameterMethodNameResolver(参数方法名称解析器) And XmlViewResolver(视图解析器)
参数方法名称解析器 1.配置依赖包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...
随机推荐
- OM模块功能&API详解
(一)销售订单概述 1.1 与车间模块关系 当使用ATO类型订单时,订单管理模块会直接在车间模块中产生任务 1.2 与库存模块关系 在销售订单中使用的物料,单位等信息均来自库存模块,在订单执行 ...
- 添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三)
添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三) 猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blo ...
- java5后的并发池
本文可作为传智播客<张孝祥-Java多线程与并发库高级应用>视频的学习记录. 为什么需要并发池 之前写并发的时候 new Thread(new Runnable(){ public voi ...
- LeetCode(37)-Minimum Depth of Binary Tree
题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...
- C# PDF Page操作——设置页面切换按钮
概述 在以下示例中,将介绍在PDF文档页面设置页面切换按钮的方法.示例中将页面切换按钮的添加分为了两种情况,一种是设置按钮跳转到首页.下页.上页或者最后一页,另一种是设置按钮跳转到指定页面.两种方法适 ...
- 一个CSS背景颜色问题
div{ background: rgba(0,0,0,.1); background-color: #19FFFFFF; } 安卓下会显示上面的透明颜色,而在iOS上则显示下面的颜色,并且其 ...
- 一篇迟到的gulp文章
前言 这篇文章本应该在去年17年写的,但因为种种原因没有写,其实主要是因为懒(捂脸).gulp出来的时间已经很早了,16年的时候还很流行,到17年就被webpack 碾压下去了,不过由于本人接触gul ...
- iframe中 父页面和子页面查找元素的方法
从父页面中查找iframe子页面中对象的方法:JS: document.getElementById('iframe').contentWindow //查找iframe加载的页面的window对象 ...
- Markdown编辑技巧
[前言] 保存Markdown的编辑技巧,写博客随笔,可以用下. [正文] 1.空格 //半角空格(英文) //全角空格(中文)
- python 定时服务模块
python定时任务使用方法如下: import sched shelder = sched.scheduler(time.time, time.sleep) shelder.enter(2, 0, ...