首页 技术 正文
技术 2022年11月12日
0 收藏 562 点赞 3,634 浏览 1719 个字

上期讲解了第一入门案例之后接下来了解一下视图解析器与URL-Pattern的配置方案

先来说视图解析器,在上次博客文章中我们完成了入门案例,接下来我们就在上一个例子中完善一下体出视图解析器

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
"><!-- 注册视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀后缀 -->
<property name="prefix" value="WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 注册控制器--> <bean id="/hello.do" class="cn.lxp.controller.MyController"></bean> </beans>

配置好视图解析器之后我们的控制器类中的锁定页面就可以直接写页面名称不用管后缀与前缀了

public class MyController implements Controller {    /**
* handleRequest 处理请求
* ModelAndView 返回的类型
*/
@Override
public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception { ModelAndView mav=new ModelAndView();
mav.addObject("msg", "我们天生爱分享!!");
//进行处理一道
mav.setViewName("index"); return mav;
}}

我们重启服务器再来访问,结果如图显示,说明我们的视图解析器起到了一定的作用!

Spring MVC之视图解析器和URL-Pattern的配置方案

下面我们来讲解url-pattern

Spring MVC之视图解析器和URL-Pattern的配置方案

Spring MVC之视图解析器和URL-Pattern的配置方案

配置成/的话会拦截到静态资源所以我们来介绍以下三种解决方案,当然不止三种

Spring MVC之视图解析器和URL-Pattern的配置方案

Spring MVC之视图解析器和URL-Pattern的配置方案

Spring MVC之视图解析器和URL-Pattern的配置方案

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,495
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,741
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298