开发SpringMVC应用的步骤
来源:互联网 发布:php加密授权 编辑:程序博客网 时间:2024/04/30 05:50
1. 在web.xml中配置相关配置
<!-- 为整个web项目加载顶层WebApplicationContext --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- WebApplicationContext地址 --><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param><!-- POST乱码过滤器 --><filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class></filter><filter-mapping> <filter-name>encodingFilter</filter-name> <servlet-name>controller</servlet-name></filter-mapping> <!-- 前端控制器 --><servlet> <servlet-name>controller</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-servlet.xml</param-value> </init-param></servlet><servlet-mapping> <servlet-name>controller</servlet-name> <url-pattern>/</url-pattern></servlet-mapping>
2.配置Spring mvc的三个组件
2.1 HandlerMapping配置
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
2.2 HandlerAdapter配置
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
2.3 ViewResolver配置
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF"/> <property name="suffix" value=".jsp"/></bean>
4.按照处理器适配器的规则开发Handler
public class HelloController implements Controller { private IHelloWorld helloWorld; public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView modelAndView = new ModelAndView("/helloWorld"); modelAndView.addObject("str",helloWorld.say()); return modelAndView; } public IHelloWorld getHelloWorld() { return helloWorld; } public void setHelloWorld(IHelloWorld helloWorld) { this.helloWorld = helloWorld; }}
5.配置handler到spring 容器当中
<bean name="/test" class="com.controller.HelloController"> <property name="helloWorld" ref="helloWorldService"/></bean>
6.配置其他相关的Bean到Spring容器中
<bean id="helloWorldService" class="com.service.impl.HelloWorldImpl"/>
7.编写展示层
0 0
- 开发SpringMVC应用的步骤
- 搭建SpringMVC应用的开发步骤
- 我的Springmvc开发详细步骤
- Struts2 应用的开发步骤
- Struts2应用的开发步骤
- Android应用的开发步骤
- 开发传感器应用的步骤
- Springmvc开发详细步骤
- SpringMVC开发步骤
- SpringMVC初级应用--第一步骤
- 开发基于ATL窗口应用的步骤
- Struts 2应用的开发步骤
- iOS开发应用上传AppStore的步骤
- springMVC入门---简单开发步骤
- 开发基于springMVC的web应用
- springmvc的创建步骤
- 创建springmvc的步骤
- SpringMVC的配置步骤
- Android6.0 Sensor架构和问题分析
- 试水Fragment(4)-重要的生命周期
- Linux命令基础
- 积木
- [23] Vijos P1781 同余方程(数论)
- 开发SpringMVC应用的步骤
- 【Python】以不定条件下兔子总数计算为例-Python中对数量规律问题的思考与延展
- thymeleaf 教程
- 和为指定数的组合个数
- JZOJ 4743 积木
- 保护模式下,读写大地址内存 & 从32位保护模式跳回16位实模式
- javascript基本语法笔记
- prim有意思。。。
- Eclipse编辑器基本设置