zoukankan      html  css  js  c++  java
  • springMVC_注解方式搭建基础环境

    ---恢复内容开始---

    一、jar包环境,web配置文件和Spring-MVC配置文件的,相关的modelAndview

    1.配置DispatcherServlet

    <servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:spring-mvc.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>

    2.配置bean.xml文件的监听器

      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:beans.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

    3.配置Spring-MVC.xml文件

    3.1配置扫描控制器Cotroller包路径和注解驱动

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

        <!-- 自动扫描 -->
        <context:component-scan base-package="springmvcpracticewebcontroller">
        </context:component-scan>
        
        <mvc:resources location="/resources/" mapping="/images/**"/>
        
        <!-- 注解驱动 -->
        <mvc:annotation-driven>
        </mvc:annotation-driven>

    3.2配置文件上传解析器

    <!-- 文件上传解析器 id 必须为multipartResolver -->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize" value="10485760">
            </property>    
        </bean>

    3.3配置内部资源解析器和静态视图资源路径

    <!-- 映射静态资源 -->
        <mvc:resources location="/images/" mapping="/images/**"/>
        <mvc:resources location="/upload/" mapping="/upload/**"/>
        
        
        <!-- 内部资源视图解析器  prefix + logicName + suffix /WEB-INF/jsps/ + index + .jsp-->
        <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/WEB-INF/jsps/"/>
            <!-- 后缀 -->
            <property name="suffix" value=".jsp"/>
        </bean>

    3.4配置beans.xml文件的Service包路径的自动扫描

    <?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:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.2.xsd ">

        <!-- 自动扫描 -->
        <context:component-scan base-package="springmvcpracticeservice"/>
        
    </beans>

    二、配置编写,person bean,personService和contorller的实体类

    三、

    ---恢复内容结束---

  • 相关阅读:
    搜房二手频道调研
    智能评论排序
    国外社交网站调研(13年9月)
    百度金融产品的几点看法
    Microvideos for Website/ products
    C#后端代码访问webapi
    基于FineUI-FineUIMVC基础版开发的通用后台框架
    EasyUI, Dialog 在框架页(ifrmae)的Top页面弹出时,拖拽Dialog边缘(以改变窗口大小),UI界面被卡死的解决办法
    在Windows上使用Docker 创建MongoDB 副本集的极简方法(翻译)
    初探ABP--记一些常见的开发问题
  • 原文地址:https://www.cnblogs.com/jinb/p/6551555.html
Copyright © 2011-2022 走看看