初学者如何搭建SpringMvc框架的模型

      相信很多初学者和我一样对于SpringMVC想的很困难,其实我们就按照平时的开发步骤进行套用就行了。


      web的基本步骤:数据库-Entity-service-mvc-ui。

      

     那下面我们就一步步的了解SpringMVC的基本运行流程,

     1.肯定是搭建运作环境。先动少改动的,web.xml。

    代码:

   

         <display-name>springMVC</display-name>
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/dispatcherServlet-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>



照片备注:


2.下面配置web.xml里面提到的//WEB-INF/dispatcherServlet-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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!-- 对src下面的包进扫描查找controller -->
    <context:component-scan base-package="mvc"/>    
    
    <mvc:annotation-driven/>
    
	<!-- 对转向页面的路径《解析》。prefix:前缀, suffix:后缀 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
		<property name="prefix" value="/WEB-INF/jsp/"/>
		<property name="suffix" value=".jsp"/>
	</bean>

</beans>

注:上门的注释大家一定要注意解析路径的前缀和后缀。

图片

 

3.  jar包的话大家没有可以加我QQ问我要289390186工作时间都行的。


4. 还需要注意的是上面路径解析的jsp文件是放在什么路径下面的

     


5.就需要去srt创建dispatcherServlet-servlet.xml中需要扫描的包MVC

6.  下面创建我们的controller

    

7. 下面我们就能简单的和web页面进行传值了,大家可以多理解。http://localhost:8080/SpringMvc/index?pa=123

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值