SSM-SpringMVC-08:SpringMVC中以继承AbstractController的方式实现处理器

释放双眼,带上耳机,听听看~!

 

 

 

————吾亦无他,唯手熟尔,谦卑若愚,好学若饥————-

 

 

 

AbstractController实现了一些特殊功能,如继承了WebContentGenerator缓存控制功能,并提供了可选的会话的串行化访问功能。而且提供了handleRequestInternal方法,因此我们应该在具体的控制器类中实现handleRequestInternal方法,而不再是handleRequest。

它可以指定请求的方式,什么请求可以访问到

 

 

简单使用:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1package cn.dawn.day04abstractController;
2
3import org.springframework.web.servlet.ModelAndView;
4import org.springframework.web.servlet.mvc.AbstractController;
5import org.springframework.web.servlet.mvc.Controller;
6
7import javax.servlet.http.HttpServletRequest;
8import javax.servlet.http.HttpServletResponse;
9
10/**
11 * Created by Dawn on 2018/3/19.
12 */
13//处理器
14public class FirstController extends AbstractController {
15
16    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
17        ModelAndView me=new ModelAndView();
18        me.setViewName("index");
19        return me;
20    }
21}
22

 

在xml配置文件中:

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1<?xml version="1.0" encoding="UTF-8"?>
2<beans xmlns="http://www.springframework.org/schema/beans"
3       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
4       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">
5
6    <!--配置bean处理器-->
7    <bean id="second" class="cn.dawn.day04abstractController.FirstController">
8        <!--可以指定访问方式-->
9        <property name="supportedMethods" value="GET,POST"></property>
10    </bean>
11    <!--视图解析器-->
12    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
13        <property name="prefix" value="/"></property>
14        <property name="suffix" value=".jsp"></property>
15    </bean>
16
17    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
18        <!--第一种方式-->
19        <!--<property name="urlMap">
20            <map>
21                <entry key="/hello">
22                    <value>second</value>
23                </entry>
24            </map>
25        </property>-->
26        <!--第二种方式-->
27        <property name="mappings">
28            <props>
29                <prop key="/hello">second</prop>
30            </props>
31        </property>
32    </bean>
33
34</beans>
35

 这种配置方法只支持,get,post俩种方式可以访问到这个处理器

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C++ explicit关键字

2022-1-11 12:36:11

安全资讯

阴阳师业原火BOSS副本12月30日推出 新御魂一览

2016-12-25 14:32:31

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索