mvc 返回字符设置(null空返回“”,xxs注入,日期转化等)

来源:互联网 发布:艾媒数据的报告 编辑:程序博客网 时间:2024/05/22 17:14
1,
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

标明版本(涉及到的都要标明)否则:
cvc-complex-type.2.1: 元素 'mvc:annotation-driven' 必须不含字符或元素信息项 [子级], 因为该类型的内容类型为空。




2,

com.fasterxml.jackson.databind.ObjectMapper
继承这个类可以过滤jsp到java传的字符如Xss注入,时间格式等
也可以处理Java对象转化为json返回jsp,时间格式,null字符集等处理,即这个是双向拦截处理主要对于@ResponseBody





<!-- 启动注解驱动的Spring MVC功能,实现前台数据的映射或操作注解 -->
<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true" >
<!--处理json等返回jsp下载问题-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>text/plain;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
<!--处理对象转化为json返回jsp,以及jsp到后台的Xss注入-->
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="objectMapper">
                    <bean class="com.esteel.until.CustomJacksonObjectMapper" />
                </property>
            </bean>
    </mvc:message-converters>
    </mvc:annotation-driven>
0 0