2.1環境準備
a.數據庫環境準備 mysql mybatis建表
b.java環境準備 jdk eclipse
c.springmvc版本 將Spring所有jar包加到工程中(一定要有Spring-webmvc-3.2.0.release.jar)
2.2需求
以案例作爲驅動 商品訂單管理
功能:商品列表查詢
2.3配置前端控制器
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>springfirst1225</display-name>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfiglocation配置springmvc加載的配置文件(配置處理器映射器,適配器等等)
如果不配置contextConfiglocation,默認加載的是/WEB-INF/servlet名稱-servlet.xml(springmvc-servlet.xml)
-->
<init-param>
<param-name>contextConfiglocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--
第一種:*.action.訪問以.action結尾的由DispatcherServlet進行解析
第二種:/.所有訪問的地址都有DispatcherServlet進行解析,對於靜態文件要配置不讓DispatcherServlet解析
使用此種方法可以實現RESTful風格的url
第三種:/*.這樣配置不對,這樣配置,最終要轉變一個jsp頁面,仍然用DispatcherServlet解析jsp,不能根據jsp頁面找到Handler,會報錯
-->
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>