SSM-SpringMVC-13:SpringMVC中XmlViewResolver视图解析器

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

 

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

 

 

还记得上篇博客提出来的问题吗?

BeanNameViewResolver视图解析器每使用一道视图,就得手工配置一道,麻烦啊,最重要的一点,如果视图多了,你这个核心的xml配置文件还怎么看?又乱又长****

 

所以XmlViewResolver这个视图解析器,就是来carry这个问题的

 

怎么解决?不懂啊?看完案例,我给你描述,现在简单提一句,就是把自己定义的视图实例提出来到一个单独的xml文件中

 

案例,紧接上篇:

新建一个xml文件,我的名字叫:ApplicationContext-day09Zview.xml

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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    <!--视图xml-->
7
8
9    <!--外部视图-->
10    <bean id="OuterViewObject" class="org.springframework.web.servlet.view.RedirectView">
11        <property name="url" value="https://www.jd.com"></property>
12    </bean>
13
14    <!--内部视图-->
15    <bean id="jstlViewObject" class="org.springframework.web.servlet.view.JstlView">
16        <property name="url" value="/second.jsp"></property>
17    </bean>
18
19
20
21</beans>
22

 

 

我把上篇博客的视图实例放到了此处,那么自己的核心配置文件怎么与之关联,就又需要考虑一下

 

自己的核心配置文件:(较上篇博客的做了一些改动)

 


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
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="myViewController" class="cn.dawn.day08ViewResolver.MyViewController">
8        <property name="methodNameResolver" ref="parameterMethodNameResolver"></property>
9    </bean>
10    <!--xml视图解析器-->
11    <bean class="org.springframework.web.servlet.view.XmlViewResolver">
12        <property name="location" value="classpath:ApplicationContext-day09Zview.xml"></property>
13    </bean>
14
15
16    <!--参数方法名称解析器-->
17    <bean id="parameterMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
18        <property name="paramName" value="actionName"></property>
19    </bean>
20
21    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
22        <!--第一种方式-->
23        <property name="urlMap">
24            <map>
25                <entry key="/doFirst">
26                    <value>myViewController</value>
27                </entry>
28            </map>
29        </property>
30    </bean>
31
32</beans>
33

 

 

 

之后只需要将web.xml改成新的这个配置文件即可

 

其它的(像页面和自定义的处理器)与之前的一般无二

 

 

 

——配置式开发springmvc结束,引入注解版—–

 

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

C++遍历文件夹

2022-1-11 12:36:11

安全运维

(图文并茂)深度学习实战(1):ubuantu下安装和配置caffe框架(cpu版)

2021-12-12 17:36:11

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