SpringMVC 控制器写多个方法(非注解方式)
Controller类有两种方法
1,implements Controller(实现Controller接口)
2,extends MultiActionController(继承 MultiActionController)
但是实现接口有缺陷,只能写一种方法(handleRequest),比如完成某一业务对象的增,删,改,查,都属于一类相关的业务。把一类相关的操作分布到不同的类去完成,违返“高内聚”的设计原则。所以一般都会采用第二种方法。
springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com" />
<bean id="irViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/page/" />
<property name="suffix" value=".jsp" />
</bean> <!-- MultiAction -->
<!-- 引入多视图控制 -->
<bean id="paramMethodResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName" value="method">
</property>
</bean>
<bean id="simpleUrlHandlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/testinterceptor">testInterceptorController</prop>
</props>
</property>
</bean>
<!-- 将多视图控制paramMethodResolver注入到自己的控制器-->
<bean id="testInterceptorController" class="com.TestInterceptorController">
<property name="methodNameResolver" ref="paramMethodResolver"></property>
</bean> </beans>
控制器:
package com; import java.util.Date; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; @SuppressWarnings("deprecation")
public class TestInterceptorController extends MultiActionController { public String show(HttpServletRequest request, HttpServletResponse response){
request.setAttribute("date", new Date());
return "show";
}
}
*这里要用request进行传值
输入访问:......?method=show
SpringMVC 控制器写多个方法(非注解方式)的更多相关文章
- springmvc2 一个控制器写多个方法(非注解方式)
出处:http://blog.csdn.net/xuewenke/article/details/23895999 springmvc2 一个控制器写多个方法(非注解方式) 分类: spring 20 ...
- SpringMVC中注解和非注解方式下的映射器和适配器总结
1. 非注解方式 1.1 处理器适配器 上一节中使用的处理器适配器是:org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapte ...
- 【SpringMVC学习03】SpringMVC中注解和非注解方式下的映射器和适配器总结
从上一篇的springmvc入门中已经看到,springmvc.xml中的配置了映射器和适配器,是使用非注解的方式来配置的,这是非注解方式的一种,这里再复习一下: 1. 非注解方式 1.1 处理器适配 ...
- Springboot使用Cookie,生成cookie,获取cookie信息(注解与非注解方式)
先 创建一个控制类吧, 其实我没有分层啊,随便做个例子: MyGetCookieController: @RestControllerpublic class MyGetCookieControlle ...
- SpringMVC的controller方法中注解方式传List参数使用@RequestBody
在SpringMVC控制器方法中使用注解方式传List类型的参数时,要使用@RequestBody注解而不是@RequestParam注解: //创建文件夹 @RequestMapping(value ...
- MyBatis学习(二):与Spring整合(非注解方式配置MyBatis)
搭建SpringMVC的-->传送门<-- 一.环境搭建: 目录结构: 引用的JAR包: 如果是Maven搭建的话,pom.xml的配置如下: <?xml version=" ...
- Spring Boot 2.x 缓存应用 Redis注解与非注解方式入门教程
Redis 在 Spring Boot 2.x 中相比 1.5.x 版本,有一些改变.redis 默认链接池,1.5.x 使用了 jedis,而2.x 使用了 lettuce Redis 接入 Spr ...
- SpringMVC知识点总结一(非注解方式的处理器与映射器配置方法)
一.SpringMVC处理请求原理图(参见以前博客) 1. 用户发送请求至前端控制器DispatcherServlet 2. DispatcherServlet收到请求调用HandlerMappi ...
- spring实战二之Bean的自动装配(非注解方式)
Bean的自动装配 自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg>元素,让Spring自动识别如何装配Bea ...
随机推荐
- yhdsir@function:php
curl 获取页面信息 function curl_get_content($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $u ...
- Data Structure Binary Tree: Level order traversal in spiral form
http://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/ #include <iostream> #includ ...
- ping: sendto: Network is unreachable【转】
本文转载自:http://blog.sina.com.cn/s/blog_640531380102wmzb.html 在我的板子上ping路由上的IP的时候可以ping通,但是ping外网的IP的时候 ...
- 郝健: Linux内存管理学习笔记-第1节课【转】
本文转载自:https://blog.csdn.net/juS3Ve/article/details/80035751 摘要 MMU与分页机制 内存区域(内存分ZONE) LinuxBuddy分配算法 ...
- <J2EE学习笔记>续上次Servlet部分提升内容 以及JSP的内容纲要
以下全部课件均来自于同济大学刘岩老师的<EnterpriseJavaProgramming> 因为授课语言问题,如果翻译有不正确之处欢迎指正 Section 1. 关于Servlet的部分 ...
- matlab之plot()函数
是个画图函数: 语法: figure(1000);hold on;plot(x,y);axis equal; 其中,x和y是某两个长度相同的列向量.比如:x=[1;2;3;4];y=[1;2;3;4] ...
- C#SocketAsyncEventArgs实现高效能多并发TCPSocket通信 (服务器实现)
http://freshflower.iteye.com/blog/2285272 想着当初到处找不到相关资料来实现.net的Socket通信的痛苦与心酸, 于是将自己写的代码公布给大家, 让大家少走 ...
- bzoj 3685
线段树 方法一: 值域线段树,递归去写的,每次节点存出现次数. 对于几个操作, 1,2 直接加减就好 ; 3,4 操作贪心往某一个方向找 .7也很简单,主要说前驱后继怎么找.我是先找这个数第几小,根据 ...
- python 之gc(回收机制)--garbage collection(GC垃圾回收)
######################引用计数######################### 引用计数:python 当中一种用来解决垃圾回收的策略之一 char 1个字节(2**8) in ...
- 「USACO08DEC」「LuoguP2921」在农场万圣节Trick or Treat on the Farm(tarjan
题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定 ...