标签简化Spring-MVC配置
新填入@RequestMapping标签
和@org.springframework.stereotype.Controller标签
这样做就是通过标签来简化之前,对HandlerMapping的配置。HandlerMapping的作用也就无非是,接收前端request,再找到指定controller。
package com.controller; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; @org.springframework.stereotype.Controller
@RequestMapping("/path01/path02")
public class HelloController implements Controller{ @Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("处理hello.form请求");
ModelAndView mv = new ModelAndView("hello");
return mv;
} @RequestMapping("/hello.form")
public String execute() throws Exception{
return "hello";
} }
这样配置后,路径就是 localhost/myspring(project's name)/path01/path02/hello.form
<?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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <mvc:annotation-driven/>
<context:component-scan base-package="com.controller"/> <!-- 定义视图解析器viewResolver -->
<bean id = "viewResolver"
class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/jsp/"/>
<property name = "suffix" value = ".jsp"/>
</bean> <!-- 控制器bean配置 -->
<bean id = "helloController"
class = "com.controller.HelloController"/>
</beans>
运行:

标签简化Spring-MVC配置的更多相关文章
- spring MVC配置详解
现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...
- Spring mvc 配置详解
现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...
- spring MVC配置详解(转)
现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...
- Spring MVC配置详解(3)
一.Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar包引入 Spring 2.5.6:spring.jar.spring-webmvc.ja ...
- Spring MVC配置静态资源和资源包
Spring MVC配置静态资源和资源包 本例映射:css目录: pom.xml <properties> <spring.version>4.3.5.RELEASE</ ...
- 最小可用 Spring MVC 配置
[最小可用 Spring MVC 配置] 1.导入有概率用到的JAR包, -> pom.xml 的更佳实践 - 1.0 <- <project xmlns="http:// ...
- Tomcat配置和Spring MVC配置
Tomcat启动时,先找系统变量CATALINA_BASE,如果没有,则找CATALINA_HOME.然后找这个变量所指的目录下的conf文件夹,从中读取配置文件.最重要的配置文件:server.xm ...
- Spring MVC 配置类 WebMvcConfigurerAdapter
WebMvcConfigurerAdapter配置类是spring提供的一种配置方式,采用JavaBean的方式替代传统的基于xml的配置来对spring框架进行自定义的配置.因此,在spring b ...
- MQTT 4 ——MQTT的Spring Mvc 配置接收字节流数据
本篇记录一下MQTT整合Spring Mvc配置直接收发字节流数据 设备方是纯C开发,并且为了交互数据的安全,将传送的数据用了AES CBC进行了加密. 接下来正常方便做法应该是 将加密后的字节流转换 ...
- 使用import简化spring的配置 spring import 标签的解析 使用import或加载spring配置时,报错误There is no ID/IDREF 多个Spring配置文件import resource路径配置
spring-import 标签的解析.使用案例: 对于spring配置文件的编写,我想,对于经历过庞大项目的人,都有那种恐惧的心理,太多的配置文件.不过,分模块都是大多数人能想到的方法,但是,怎么分 ...
随机推荐
- CUnit的用法
转自:http://blog.csdn.net/scucj/article/details/4385630/ CUnit下载地址: http://sourceforge.net/projects/cu ...
- C++ dll调用
HINSTANCE PH=LoadLibrary(_T("APlayerCaller.dll")); HWND hwnd = AfxGetMainWnd()->m_hWnd; ...
- MongoDB中的连接池
参见 http://www.cnblogs.com/huangfox/archive/2012/04/01/2428947.html
- C盘实际占用容量比显示的要少
1.问题 服务器是Window Server 2008 R2,就几天时间,60G的C盘容量一下子满了,选中所有的文件,占用才20多G. 2.原因 1).有的文件没有系统管理员权限,大小不会显示出来. ...
- Swift3.0基础语法学习<五>
异常处理: // // ViewController5.swift // SwiftBasicDemo // // Created by 思 彭 on 16/11/16. // Copyright © ...
- Selenium2+python自动化24-js处理富文本(带iframe)
前言 上一篇Selenium2+python自动化23-富文本(自动发帖)解决了富文本上iframe问题,其实没什么特别之处,主要是iframe的切换,本篇讲解通过js的方法处理富文本上iframe的 ...
- 解决 HttpClient 模拟 http 的get 请求后 ,出现 403 错误
解决方法: URI uri = builder.build(); // 创建http GET请求 HttpGet httpGet = new HttpGet(uri); httpGet.setHead ...
- WPF中ListBox的样式设置
设置之后的效果为
- 2016/10/28 很久没更了 leetcode解题 3sum
15. 3Sum Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Fi ...
- opps kio
Unable to handle kernel NULL pointer dereference at virtual address 00000008pgd = c7090000, hw pgd = ...