SpringMVC详细示例实战教程

SpringMVC详细示例实战教程

编程入门hacker2017-02-16 9:20:139061A+A-

SpringMVC学习笔记----






一、SpringMVC基础入门,创建一个HelloWorld程序

1.首先,导入SpringMVC需要的jar包。



2.添加Web.xml配置文件中关于SpringMVC的配置


  <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->

  <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:springmvc-servlet.xml</param-value>

        </init-param>

        <!-- <load-on-startup>1</load-on-startup> -->

  </servlet>


  <servlet-mapping>

      <servlet-name>springmvc</servlet-name>

      <url-pattern>/</url-pattern>

  </servlet-mapping> 

3.在src下添加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"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd

        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">                    


    <!-- scan the package and the sub package -->

    <context:component-scan base-package="test.SpringMVC"/>


    <!-- don't handle the static resource -->

    <mvc:default-servlet-handler />


    <!-- if you use annotation you must configure following setting -->

    <mvc:annotation-driven />

    

    <!-- configure the InternalResourceViewResolver -->

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 

            id="internalResourceViewResolver">

        <!-- 前缀 -->

        <property name="prefix" value="/WEB-INF/jsp/" />

        <!-- 后缀 -->

    


点击这里复制本文地址 以上内容由黑资讯整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
  • 1条评论
  • 礼忱野浓2022-05-29 05:48:44
  • ckage and the sub package -->    <context:component-scan base-package=&qu

支持Ctrl+Enter提交

黑资讯 © All Rights Reserved.  
Copyright Copyright 2015-2020 黑资讯
滇ICP备19002590号-1
Powered by 黑客资讯 Themes by 如有不合适之处联系我们
网站地图| 发展历程| 留言建议| 网站管理