maven工程web层的spring-mvc配置文档

1、避免IE浏览器发送ajax请求时,出现下载的情况

2、采用springmvc自带的JSON转换工具,支持@ResponseBody注解

3、对模型视图添加前后缀

4、controller层注入

下面是例子:

<?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.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- 避免IE在ajax请求时,返回json出现下载 -->
    <bean id="mappingJackson2HttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
                <value>text/json;charset=UTF-8</value>
                <value>application/json;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 采用SpringMVC自带的JSON转换工具,支持@ResponseBody注解 -->
    <bean
        class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJackson2HttpMessageConverter" />
            </list>
        </property>
    </bean>

    <!-- 对模型视图添加前后缀 -->
    <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/view/" p:suffix=".jsp" /> -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/view/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!-- 扫描controller(controller层注入) -->
    <mvc:annotation-driven />
    <context:component-scan base-package="com.mmc.d4alc.controller" />

    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/file/" mapping="/file/**" />
    <mvc:resources location="/" mapping="/*.txt" />

</beans>
时间: 2024-08-08 04:59:33

maven工程web层的spring-mvc配置文档的相关文章

maven工程web层的spring配置文档

1.引入jdbc配置文档 2.扫描文件 3.上传文件的设置 下面是例子: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi

maven工程web层的web.xml配置文档内容

下面是web层,web.xml配置文档里面需要配置的东西: 1.lo4j配置 2.读取spring文件配置 3.设计路径变量值 4.spring字符集过滤器 5.登陆过滤器 6.springMVC核心配置 7.session过期时间 8.错误页面跳转 以下是实例: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSch

Spring MVC 指导文档解读(一)

22.1 指导文档章节 In the Web MVC framework, each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext. 解读 一. DispatcherServlet 可以定义多个 二. root WebApplicationContext 适用于所有的 Dispat

maven工程web层的spring-mybatis配置文档

1.配置数据库的链接 2.扫描mapper文件 3.spring与mybatis整合配置,扫描所有dao 4.对数据源进行事务管理 下面是例子: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSch

Spring MVC 指导文档解读(二)

Special Bean Types In the WebApplicationContext 解读 1.WebApplicationContext 特有的几种 Bean Types 2. 也表明 与之相对的 还有 ApplicationContext 下面这几种特有的 web bean types 也理应定义到 web 的上下文配置文件中,比如 a-servlet.xml Table 22.1. Special bean types in the WebApplicationContext B

spring mvc配置 + dbcp数据源+jdbcTemplate

spring mvc配置 + dbcp数据源+jdbcTemplate 最近打算仔细研究一下spring,就从用了2年的spring mvc开始吧,初学者可以看看,大神就pass好了,呵呵.... 首先去spring官网下载完整的spring包,包含libs, docs和schema,spring的版本是3.2.4 我们来看一下spring的lib包都有那些内容: 上面图片中除红色框内的两个jar其它都是spring官方提供的jar包,红色框内的jar我们在配置事务的时候会用到,我们一会再说.我

最小可用 Spring MVC 配置

[最小可用 Spring MVC 配置] 1.导入有概率用到的JAR包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/mave

springboot Serving Web Content with Spring MVC

Serving Web Content with Spring MVC This guide walks you through the process of creating a "hello world" web site with Spring. What you'll build You'll build an application that has a static home page, and also will accept HTTP GET requests at:

spring MVC配置详解[转]

现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过要想灵活运用Spring MVC来应对大多数的Web开发,就必须要掌握它的配置及原理. 一.Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar包引入 Spring 2.5.6:spring.jar.spring-webmvc.jar.comm