
搭建springweb项目 需要五步
1,前端控制器 dispatcherservlet,在web.xml中配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Spring_Mybatis_zhengHe_linaXi</display-name>
<!-- spring前端控制器 (程序入口) -->
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
2,处理器映射器 handlermapping web.xml 文件中配置的文件中配置,上边配置的是在classpath:spring-mvc.xml文件中
3,处理器适配器 handler adapter
4,视图解析器 viewresolver
5,注册controller
<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/tx
http://www.springframework.org/schema/tx/spring-tx-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/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 2,3,步 配置处理器映射器和处理器适配器 start -->
<!-- mvc:annotation-driven 用于代替注解处理器映射器和注解处理器适配器的配置,即有了这个标签就自动配置注解处理器适配和注解处理器适配器,就可以不用再单独配置适配器和映射器了.-->
<mvc:annotation-driven />
<!-- 配置处理器映射器和处理器适配器 end -->
<!-- 4步,视图解析器 start -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 视图解析器 end -->
<!-- 5,注册controller start -->
<!-- 注册controller 不然处理器映射器无法找到handler(controller) 交给处理器适配器执行-->
<!-- 也可以使用注解扫描<context:component-scan base-package="扫描包路径"/>,使用注解扫描可以不用每写一个controller都要注册一次,如jeecms就是写一个contrller,service就要注册一次。-->
<!-- <bean class="com.ct.ssmlianxi.IndexController"></bean> -->
<context:component-scan base-package="com.ct.ssmlianxi"/>
<!-- 注册controller end -->
</beans>
593

被折叠的 条评论
为什么被折叠?



