JAVA-SpringMVC基于注解模式第一个应用
项目文件结构

1. web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0"> <display-name>test</display-name>
<!-- 配置springmvc前端配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocaltion</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- 配置注解扫描包 -->
<context:component-scan base-package="com.luo.test"/>
<!--注册用于支持基于朱姐的控制器的请求处理方法的beans -->
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/" mapping="/*.html"/>
<!-- 配置前端页面的映射前缀和后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀,view的路径 -->
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
3.controller
package com.luo.test; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloController {
private static final Log logger=LogFactory.getLog(HelloController.class); @RequestMapping(value="/hello")
public String Hello(){
logger.info("Hello Called");
return "hello";
}
}
4.view
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>hello</h1>
</body>
</html>
5.运行结果

注解模式的原理:通过扫描注解文件找到Controller从而找到对应的view
JAVA-SpringMVC基于注解模式第一个应用的更多相关文章
- 04springMVC结构,mvc模式,spring-mvc流程,spring-mvc的第一个例子,三种handlerMapping,几种控制器,springmvc基于注解的开发,文件上传,拦截器,s
1. Spring-mvc介绍 1.1市面上流行的框架 Struts2(比较多) Springmvc(比较多而且属于上升的趋势) Struts1(即将被淘汰) 其他 1.2 spring-mv ...
- springMVC基于注解的控制器
springMVC基于注解的控制器 springMVC基于注解的控制器的优点有两个: 1.控制器可以处理多个动作,这就允许将相关操作写在一个类中. 2.控制器的请求映射不需要存储在配置文件中.使用re ...
- 缓存初解(五)---SpringMVC基于注解的缓存配置--web应用实例
之前为大家介绍了如何使用spring注解来进行缓存配置 (EHCache 和 OSCache)的简单的例子,详见 Spring基于注解的缓存配置--EHCache AND OSCache 现在介绍一下 ...
- springMVC 基于注解的controller
概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...
- SpringMVC 基于注解的Controller详解
本文出处 http://blog.csdn.net/lufeng20/article/details/7598801 概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spri ...
- java Spring 基于注解的配置(一)
注解引用:1.service.xml 配置注解模式 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- SpringMVC 基于注解的Controller @RequestMapping @RequestParam..
概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...
- springmvc基于注解的权限控制
一.权限码 /** * @Title: AuthCode.java * @Package cn.com.kamfu.auth * @Description: TODO(用一句话描述该文件做什么) * ...
- SpringMVC基于注解开发的步骤
基于xml配置 .1准备好以下相关jar包 .2创建Maven项目使用骨架 (这里选择第二个以webapp结尾的非第一个) 给项目起个名字 这里可以更改maven本地仓库(依赖包所存放的地方)的路径 ...
随机推荐
- poj-3352-Road Construction-缩点
做法: 把所有的边双联通分量缩成一个点. 之后建树,然后求出这个树中度为1的点. #include<stdio.h> #include<iostream> #include&l ...
- [.NET] [.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=
[.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=- 识别方法: 如果无法调戏,请上传附件艾特我.............发帖不易啊..身处大西 ...
- MySQL5.6的my.ini配置
下面这个配置在现网服务器上跑了两年了,里面多项参数都有调整过,这个算是最终的一个配置,这个配置不一定适合每种项目,仅供参考. 如果MySQL出现异常:Out of memory 需要修改这几个参数: ...
- 为Qemu aarch32添加BeautifulSoup4模块
环境 Qemu:2.8.0 开发板:vexpress-ca9 概述 上一篇博文已经可以让我们的开发板可以成功的ping通百度了,据说Python的网络功能也很强大,而Beautiful Soup是 ...
- AngularJS路由系列(5)-- UI-Router的路由约束、Resolve属性、路由附加数据、路由进入退出事件
本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● UI-Router约束路由参数● UI-Router的Resolve属性● UI-Router给路由附加数据● UI- ...
- Android Service总结03 之被启动的服务 -- Started Service
Android Service总结03 之被启动的服务 -- Started Service 版本 版本说明 发布时间 发布人 V1.0 添加了Service的介绍和示例 2013-03-17 Sky ...
- C#编程(五十)----------栈
栈 栈与队列是一个非常类似的容器,他们的区别在于队列是先进先出,而栈是后进先出. Stack与Stack<T>,像队列一样,栈也提供了泛型与非泛型版本. Stack的方法: 方法 说明 P ...
- 解决克隆 centos虚拟机后修改克隆后的机器的ip、mac、uuid失败的问题
解决办法: So here's how we fix it: Remove the kernel's networking interface rules file so that it ca ...
- ios成长之每日一遍(day 5)
iOS 屏幕方向那点事儿http://zhenby.com/blog/2013/08/20/talk-ios-orientation/ 针对当前的屏幕方向进行对应的代码布局 BIDViewContro ...
- LeakCanary,30分钟从入门到精通
简述 在性能优化中,内存是一个不得不聊的话题:然而内存泄漏,显示已经成为内存优化的一个重量级的方向.当前流行的内存泄漏分析工具中,不得不提的就是LeakCanary框架:这是一个集成方便, 使用便捷, ...