19-spring学习-springMVC环境配置
生活随笔
收集整理的這篇文章主要介紹了
19-spring学习-springMVC环境配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
新建一共環境,添加spring支持,就可以開發springMVC了。
既然是springMVC,就必須為其定義相關配置。
1,springMVC所有配置都需要在applicationContext.xml中定義。
范例:修改配置文件
添加這幾個支持:
?發現配置中已經支持了
對springMVC進行annotation的配置
<!-- SpringMVC也是基于Annotaion實現的配置,啟用annotation --><context:annotation-config/> <!-- 支持annotation --><context:component-scan base-package="com.SpringMVC"/> <!-- 指定掃描包 --><!-- 定義springMVC處理 ,表示springMVC中將支持annotation--><mvc:annotation-driven/><mvc:default-servlet-handler/>2,配置web.xml文件
最好MVC設計,所有的控制器依然使用Servlet完成,而springMVC支持支持Servlet處理。
Servelet類: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" version="3.1"><display-name>SpringMVC</display-name><!-- 此部分的操作是負責Spring容器啟動的,即便使用springMVC也不能缺少此配置 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param><!-- 配置springMVC之中要使用的控制器 --><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:applicationContext.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>SpringMVC</servlet-name><url-pattern>*.action</url-pattern></servlet-mapping></web-app>此處使用了servelet進行了所有action的處理,那么也就證明了,在開發中,過濾器可以實現所有驗證操作。
?
?
?
?
轉載于:https://www.cnblogs.com/alsf/p/8215767.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的19-spring学习-springMVC环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动端开发尺寸规范
- 下一篇: requests + Beautiful