zoukankan      html  css  js  c++  java
  • SSM controller返回json中文乱码解决方法

    方法1:

    @RequestMapping(value="/aliang",produces = "text/plain;charset=utf-8")
    @ResponseBody
    需要在每一个的方法中都要写上 produces = "text/plain;charset=utf-8"

    方法1:

    <mvc:annotation-driven >
    <mvc:message-converters register-defaults="true">
    <bean class="org.springframework.http.converter.StringHttpMessageConverter" >
    <property name = "supportedMediaTypes">
    <list>
    <value>application/json;charset=utf-8</value>
    <value>text/html;charset=utf-8</value>
    <!-- application 可以在任意 form 表单里面 enctype 属性默认找到 -->
    <value>application/x-www-form-urlencoded</value>
    </list>
    </property>
    </bean>
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" ></bean>
    </mvc:message-converters>
    </mvc:annotation-driven>
    这种方法只需要在 spring-mvc.xml 配置文件中配置一次就好,省去了我们重复写的麻烦,配置内容如上。
    注意:
    org.springframework.http.converter.json.MappingJacksonHttpMessageConverter(个人用这个成功)
    可能出现不兼容情况时使用:
    org.springframework.http.converter.json.MappingJackson2HttpMessageConverter(网上查询说的是这个,但运行方法时报错)





  • 相关阅读:
    12 KLT算法
    1- js vue.js
    复用代码
    计算两个日期相隔的天数(jodd)
    [转]ORA-00907: 缺失右括号
    [转]sql server 数据库日期格式化函数
    [Oralce]Oralce格式化日期
    myeclipse内存配置
    cookie 编码问题
    [转]Oracle 操作字符串的函数
  • 原文地址:https://www.cnblogs.com/cai170221/p/13191048.html
Copyright © 2011-2022 走看看