关注此标签,是在项目中有使用

<!-- 解决@ResponseBody 的实现类其默认的编码是 iso-8859-1的问题 -->
<mvc:annotation-driven>
<mvc:message-converters>
<!-- default StringHttpMessageConverter, solve encoding problem -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
<property name="writeAcceptCharset" value="false" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
其中编码的设置写法有多种,上面是使用的构造参数的形式。
还可以设置MediaType:
 
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

  

平常一般的使用就是直接配置:

<mvc:annotation-driven />

  

那么这个标签的作用是什么:
 
基本上就是解析到Controller的,如果不配置,就不走Controller。
 
这个标签注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例
标签配置的这2个实例可以根据classpath中的内容默认提供以下功能:
1、支持spring3的javaBeans属性编辑器数据绑定时的类型转换服务。
类型转换服务实例默认为org.springframework.format.support.FormattingConversionServiceFactoryBean。
可以覆盖conversion-service属性来指定类型转换服务实例类。
2、支持@NumberFormat 注解格式化数字类型字段。
3、@DateTimeFormat注解格式化 Date, Calendar, Long和 Joda Time(如classpath下存在Joda Time 1.3或更高版本)字段
4、支持@Valid注解验证控制器数据,classpath中需JSR-303的**。
可以使用setting明确的配置
5、支持读写xml,classpath中需JAXB 。
6、支持读写json,classpath中需Jackson 。
 
要使用spring mvc中的@Controller注解,就必须要配置<mvc:annotation-driven />,否则org.springframework.web.servlet.DispatcherServlet无法找到控制器并把请求分发到控制器。
 
而項目中的使用是一种扩展使用,可以对转换年的文本数据,比如JSON数据进行修改默认编码。
 

【Spring】mvc:annotation-driven 使用的更多相关文章

  1. [Spring MVC] - Annotation验证

    使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotat ...

  2. spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例

    在写一个使用spring3 的form标签的例子时,一直报错,错误信息为:java.lang.IllegalStateException: Neither BindingResult nor plai ...

  3. Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable--转载

    原文地址: @RequestMapping is one of the most widely used Spring MVC annotation.org.springframework.web.b ...

  4. [转] Spring MVC sample application for downloading files

    http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...

  5. Spring MVC文件上传教程

    1- 介绍 这篇教程文章是基于 Spring MVC来实现文件的上传功能,这里主要是实现两个功能:1.上传单个文件并将其移动到对应的上传目录:2.一次上传多个文件并将它们存储在指定文件夹下,接下来我们 ...

  6. Spring MVC配置静态资源和资源包教程

    1- 介绍 这篇教程文章是基于: Spring 4 MVC 2- 创建一个项目 File/New/Other.. 输入: Group ID: com.yiibai Artifact ID: Sprin ...

  7. SSM(spring mvc+spring+mybatis)学习路径——2-1、spring MVC入门

    目录 2-1 Spring MVC起步 一.回顾Servlet 二.SpringMVC简介 三.搭建SpringMVC第一个案例 四.简单流程及配置 五.使用注解开发Controller 六.参数绑定 ...

  8. Spring MVC 学习笔记3 - 利用Default Annotation 模式获取请求,使Controller与View对应,并传值。

    1. WEB-INF/web.xml 这里定义了获取请求后,执行的第一步.抓取请求. <servlet> <servlet-name>appServlet</servle ...

  9. spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on

    spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on

  10. springboot Serving Web Content with Spring MVC

    Serving Web Content with Spring MVC This guide walks you through the process of creating a "hel ...

随机推荐

  1. vue学习(5)-评论功能(利用父组件的方法)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 1 .net 用事物提交执行存储过程

    public static void delModelReturn(string performanceId,DateTime? effectiveDate=null) { using (SqlCon ...

  3. 描述Cookie和Session的作用,区别和各自的应用范围,Session工作原理

    Session用于保存每个用户的专用信息. 每个客户端用户访问时,服务器都为每个用户分配一个唯一的会话ID(Session ID) . 她的生存期是用户持续请求时间再加上一段时间(一般是20分钟左右) ...

  4. js jquery 动态添加表格

    for循环将你要添加的标签写上,然后直接var talbeAdd=""for(){ tableAdd+="<tr><td>这儿写你要添加的内容&l ...

  5. 使用hbuilder打包时,调用地图和相机

    <template> <div class="comCon"> <!-- 你是头部区域的内容 --> <headback class=&q ...

  6. Nginx自动加载配置文件方案

    nginx自动加载配置文件方案一.nginx+consul+consul-template实现过程:consul作为服务发现软件,consul-template作为nginx配置文件的模板,consu ...

  7. bom and dom

    bom:Broswer Object Model: 浏览器对象模型- navigator: 获取客户机的信息(浏览器的信息)document.write(navigator.appName);- sc ...

  8. BLE各版本新功能总结

    文章转载自:http://www.sunyouqun.com/2017/04/ 协议发布时间 协议版本 2016/12 Bluetooth 5 2014/12 Bluetooth 4.2 2013/1 ...

  9. c++ mfc和win32项目

    win32项目是一个底层的窗口的实现过程,它采用的库仅仅是windows.h,我们通过winain作为函数的入口,然后经过窗口类的内容的填写,窗口的注册,创建,显示刷新,到最后的消息循环,这是一个wi ...

  10. Linux系统的grub和BIOS加密

    启动流程: BIOS ——> MBR(主引导记录,找到系统在哪个分区) ——> boot loader(grub) ——>kernel(内核)——>进入启动级别init 硬盘的 ...