博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springMVC_注解方式搭建基础环境
阅读量:4558 次
发布时间:2019-06-08

本文共 2926 字,大约阅读时间需要 9 分钟。

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

一、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="springmvcpractice\web\controller">
    </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="springmvcpractice\service"/>
    
</beans>

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

三、

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

转载于:https://www.cnblogs.com/jinb/p/6551555.html

你可能感兴趣的文章
topcoder 673
查看>>
Java中一些常用的类,包,接口
查看>>
下载特定区域内街景照片数据 | Download Street View Photos within Selected Region
查看>>
StarUML 破解方法
查看>>
C语言结构体
查看>>
[转]Tribon船体生产设计应用
查看>>
easy ui datagrid 让某行复选框不能选中
查看>>
第六周作业
查看>>
关于adb端口被占用的解决办法
查看>>
php 部分内置函数的使用
查看>>
字符串处理技巧
查看>>
归档及压缩命令
查看>>
Mybatis步骤
查看>>
WPF自定义控件之扩展原生控件
查看>>
《区块链100问》笔记整理——42~49问
查看>>
使用Jquery+EasyUI 进行框架项目开发案例讲解之二---用户管理源码分享
查看>>
深入理解计算机系统(1.4)---并发与并行、浅谈抽象
查看>>
函数依赖的公理化系统
查看>>
rabbitmq学习(四):利用rabbitmq实现远程rpc调用
查看>>
侯捷C++学习(二)
查看>>