Springmvc入门

 Spring入门

 

Springmvc是什么

 

 

Spring web mvcStruts2属于表现层的框架,都是web端的框架,是spring的一部分

结构:

 

 

Spirngmvc的流程处理:

 

 

 

入门程序

需求:使用浏览器显示商品列表

首先创建一个web工程叫springmvc03

 

 

 在导包

 

 

 

 

 

 

 

 

加入配置文件

 

创建config资源文件夹,

 

 

 

 在config里创建核心配置文件 

springmvc.xml

粘贴约束和配置controller扫描包

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    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-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <!-- 配置controller扫描包 -->
    <context:component-scan base-package="cn.springmvc.controller" />

</beans>

这个扫描包是专门扫描controller的注解(包名要改的,这个controller就是上图的处理器 就是以前的web层,一个表对应一个controller)

配置前端控制器

在web.xml配置前端控制器

<!-- 配置SpringMVC前端控制器 -->
    <servlet>
        <servlet-name>springmvc-first</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 指定SpringMVC配置文件 -->
        <!-- SpringMVC的配置文件的默认路径是/WEB-INF/${servlet-name}-servlet.xml -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc-first</servlet-name>
        <!-- 设置所有以action结尾的请求进入SpringMVC -->
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

 加入jsp页面

 

 

 

创建商品pojo

 

 

 

 

 

 点出来get set tostring 空惨构造 有参构造

在创建

 

 

 商品展示

 

 

posted @ 2020-04-08 19:21  邢昊天  阅读(127)  评论(0)    收藏  举报