说明: 使用springmvc已经半年多了,说真的刚开始的时候我只是听说过,从来都没有用过,来了之后老大让直接上手我也只是模仿,其中原理一概不知。
现在我也是一知半解,不过自己从来没有搭建过环境,今天闲下来网上搜点资料自己着手搭建一个springmvc项目。
第一步: 引入springmvc开发所需要的jar包
现在我也是一知半解,不过自己从来没有搭建过环境,今天闲下来网上搜点资料自己着手搭建一个springmvc项目。
第一步: 引入springmvc开发所需要的jar包
第二步:搭建springmvc项目,设置配置文件
<span style="font-size:18px;"><span style="color:#ff0000;"> 先配置web.xml</span>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping></span>
<span style="font-size:18px;"> <span style="color:#ff0000;"> 其次配置springmvc-servlet.xml</span>
<?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.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
<!--基于注解的开发-->
<mvc:annotation-driven/>
<context:component-scan base-package="com.soufun.act"/>
<!-- 前缀+ viewName +后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- webroot到某一指定的文件夹的路径 -->
<property name="prefix" value="/WEB-INF/jsp/"></property>
<!-- 视图名称的后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
</beans></span>
第三步:写好前台和后台代码。
这些都简单,可以自己上网搜,主要是搭好环境。