迁移应用进入基于Annotation MVC的spring 2.5
来源:互联网 发布:ps淘宝主图制作视频 编辑:程序博客网 时间:2024/06/01 21:11
Spring 2.5引入了基于Annotation配置的MVC controllers。这篇简短的文章介绍了需要如何迁移你的spring 2.0应用到spring 2.5,至少是需要迁移MVC相关的应用。
首先保证你已经将spring-webmvc.jar放在你的classpath内,DispatcherServlet不再是spring.jar的一部分,现在是在一个单独的模块内。
任何controller class能够通过一到两种方式设置,controller能够控制一个或者多个action。下面是一个包含三个独立action基本的多action controller例子。
即使这是一个最简单的例子,有一些重要的地方需要注意,尤其你使用的是spring早期版本。第一,你应该注意到controller是POJO,它没有扩展AbstractController,或者其他controller class,你在spring早期版本会这么做,第二,注意annotations,我已经通过@Controller annotation来标记处controller本身,用@RequestMapping annotations标记独立的methods。我也通过annotation做URL mapping。最后,用request URL来定位logic view name,如不指定DispatcherServlet会自动匹配/index.htm到logical name "index"等.
application context config file 配置如下:
如果你想了解spring MVC深度配置请看Annotated Web MVC Controllers in Spring 2.5.
如果你想配置应用程序其他层,请看Annotation-Based Autowiring in Spring 2.5
首先保证你已经将spring-webmvc.jar放在你的classpath内,DispatcherServlet不再是spring.jar的一部分,现在是在一个单独的模块内。
任何controller class能够通过一到两种方式设置,controller能够控制一个或者多个action。下面是一个包含三个独立action基本的多action controller例子。
- package demo;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- @Controller
- public class SimpleController {
- @RequestMapping("/index.html")
- public void indexHandler() {
- }
- @RequestMapping("/about.html")
- public void aboutHandler() {
- }
- @RequestMapping("/admin.html")
- public void adminHandler() {
- }
- }
即使这是一个最简单的例子,有一些重要的地方需要注意,尤其你使用的是spring早期版本。第一,你应该注意到controller是POJO,它没有扩展AbstractController,或者其他controller class,你在spring早期版本会这么做,第二,注意annotations,我已经通过@Controller annotation来标记处controller本身,用@RequestMapping annotations标记独立的methods。我也通过annotation做URL mapping。最后,用request URL来定位logic view name,如不指定DispatcherServlet会自动匹配/index.htm到logical name "index"等.
application context config file 配置如下:
- <?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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-2.5.xsd">
- <context:component-scan base-package="demo"/>
- <bean id="viewResolver"
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/jsp/"/>
- <property name="suffix" value=".jsp"/>
- </bean>
- </beans>
如果你想了解spring MVC深度配置请看Annotated Web MVC Controllers in Spring 2.5.
如果你想配置应用程序其他层,请看Annotation-Based Autowiring in Spring 2.5
- 迁移应用进入基于Annotation MVC的spring 2.5
- 迁移应用进入基于Annotation MVC的spring 2.5
- 基于注解(annotation)的第一个Spring MVC 应用
- Spring MVC Controller基于Annotation的两种使用方式
- 一种基于annotation的Spring-mvc权限控制方法
- 一个简单的基于注解的 Controller (spring 2.5 annotation 方式实现mvc )
- 一个简单的基于注解的 Controller (spring 2.5 annotation 方式实现mvc )
- 一个简单的基于注解的 Controller (spring 2.5 annotation 方式实现mvc )
- spring mvc annotation 的例子
- 把基于web.xml的应用迁移到Spring Boot
- Spring Web MVC简介 、基于XML配置的MVC应用 、基于注解配置的MVC应用
- spring的IOC基于annotation
- spring的IOC基于annotation
- Spring-基于Annotation的Advice
- 使用 Spring 2.5 基于注解驱动的 Spring MVC(应用篇)
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- Spring中<mvc:annotation-driven />的作用
- 基于Spring MVC的Web应用开发(5) - Redirect
- 主题 : hibernate中POJO一定要实现Serializable接口吗?这样做的目的是什么?
- 认识ASP.NET配置文件Web.config
- java中serializable的意义是什么?
- C语言文件操作简易代码
- java中的Serializable接口作用
- 迁移应用进入基于Annotation MVC的spring 2.5
- Java 泛型的理解与等价实现
- 只有80后才能懂得的生活规则
- Java 5 泛型深入研究
- syslogd
- 励志的语句,值得收藏
- c# serializabl e
- 泛型DAO和Spring的事务配置问题
- [Err0134]请求的服务不存在(arcims)