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本地仓库(依赖包所存放的地方)的路径 ... 
随机推荐
- IEEEXtreme Practice Community  Xtreme9.0 - Digit Fun!
			Xtreme9.0 - Digit Fun! 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/di ... 
- @Transactional导致无法动态数据源切换
			公司目前数据源为主从模式:主库可读写,从库只负责读.使用spring-jdbc提供的AbstractRoutingDataSource结合ThreadLocal存储key,实现数据源动态切换. 最近项 ... 
- Maven学习——修改Maven的本地仓库路径
			安装Maven后我们会在用户目录下发现.m2 文件夹.默认情况下,该文件夹下放置了Maven本地仓库.m2/repository.所有的Maven构件(artifact)都被存储到该仓库中,以方便重用 ... 
- 收集的一些MikroTik RouterOS 5.x破解版
			链接:https://pan.baidu.com/s/1RyREMfrpLkpQ-AIcDQES_Q 密码:byhd 
- STM32 通用定时器相关寄存器
			TIMx_CR1(控制寄存器1) 9-8位:CKD[1:0]时钟分频因子,定义在定时器时钟(CK_INT)频率与数字滤波器(ETR,TIx)使用的采样频率之间的分频比例. 定义:00(tDTS = t ... 
- LOG EXPLORER   ApexSQL Log
			http://www.minisoft.cn/ https://www.apexsql.com/sql_tools_log.aspx 
- 理解  process.initgroups(user, extra_group)
			这个函数是对 linux C函数 initgroups() 的包装 node.js 官方文档非常含糊,还是看 linux C函数文档的解释!非常清楚明确. The initgroups() fun ... 
- drp错误集锦---“Cannot return from outside a function or method”
			好久都不动的项目,今天打开项目突然是红色感叹号.详细错误表现为: 也就是说,如今MyEclipse已经不识别在JSP页面中使用的return方法了(并且不止一处这种警告),那怎么办?????顿时闹钟一 ... 
- 在Visual Studio中使用活动图描述业务流程
			当希望描述某个流程的时候,用活动图表示. 在项目中添加一个名称为"Shopping"的文件夹. 把"Orders Model"这个UML类图拖放到Shoppin ... 
- ASP.NET MVC与Sql Server交互, 插入数据
			在"ASP.NET MVC与Sql Server建立连接"中,与Sql Server建立了连接.本篇实践向Sql Server中插入数据. 在数据库帮助类中增加插入数据的方法. p ... 
