SpringMVC入门程序(一)

SpringMVC入门程序


1.需求

查询商品信息

2.开发环境

java:1.7

eclise:MARS.1

tomcat:7.0.

springmvc:3.2

springmvc是spring一个组成部分,依赖spring的其它的包的,需要将spring的所有jar包放到工程。


工程结构


3.前端控制器开发

DispatcherServlet是一个serlvet,需要在web.xml中配置。


注意:

1.如果不配置contextConfigLocation,默认加载/WEB-INF/servlet名称+"-serlvet.xml"即:springmvc-serlvet.xml

2.配置url-pattern时注意事项

第一种:*.action或*.do等,请求以.action或.do结尾 的由前端控制器解析

第二种:/,所有的请求全部由前端控制器解析,会把所有的包括静态资源 (csshtmljs)也解析,前端控制器无法解析静态资源,特殊处理静态资源访问不通过前端控制器解析

第三种:/*,此方法存在问题,请求需要最终转发到jsp,此方法前端控制器把转发的jsp也解析了,前端控制器无法解析jsp的,所以此方法不能使用。


4.配置处理器映射器

编写springmvc.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:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-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/context

http://www.springframework.org/schema/context/spring-context-3.2.xsd 

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

</beans>

非注解的处理器适配器。

 

springmvc.xml文件配置如下:

<beanclass="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> 


4.Handler开发

功能:查询商品信息,商品信息先通过静态数据表示。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值