當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringMVC入门案例细节分析
生活随笔
收集整理的這篇文章主要介紹了
SpringMVC入门案例细节分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、流程
1)、導包
2)、寫配置;
? ? ?1)web.xml可能要寫什么
? ? ? ? ? 配置springmvc的前端控制器,指定springmvc配置文件位置
<!-- The front controller of this Spring Web application, responsible forhandling all application requests --><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>2)框架自身可能要寫什么
3)、測試
HelloWorld細節:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <!--suppress ALL --> <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_3_0.xsd"id="WebApp_ID" version="3.0"><display-name>2.SpringMVC_helloworld</display-name><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><!-- The front controller of this Spring Web application, responsible for handling all application requests --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><!-- *.do *.action *.haha --><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>springmvc-servlet.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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><context:component-scan base-package="com.atguigu"></context:component-scan><!-- 視圖解析器,可以簡化方法的返回值,返回值就是作為目標頁面地址,只不過視圖解析器可以幫我們拼串--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"></property><property name="suffix" value=".jsp"></property></bean></beans>?
總結
以上是生活随笔為你收集整理的SpringMVC入门案例细节分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: @pathVariable 映射URL
- 下一篇: Rest风格的URL地址约束||高版本T