亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - SpringMVC4.3.7在使用@ResponseBody注解并返回含有中文字符串時字符串顯示為問號的問題
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-04-18 10:49:27
0
3
679

實際上是想用來做JSON的返回,團隊比較習(xí)慣用org.json。。。。

在項目中使用了@ResponseBody來注解一個返回值為String的函數(shù)。函數(shù)里邊獲取了一些鍵值對,鍵值對用org.json轉(zhuǎn)成了json格式,然而在輸出的時候出了問題。響應(yīng)結(jié)果中所有的中文都變成了問號,而在return前直接用System.out.println輸出到控制臺卻不是亂碼或者問號。在網(wǎng)上搜了一些解決方案,不管是加在RequestMapping里的content-type(完全看不到變化)還是加在xml的annotation-driven(直接編輯器保錯找不見這么個用法)。求教這個版本的SpringMVC應(yīng)該如何從根本上解決掉亂碼問題?
至于為啥不用直接返回Jackson的生成方式,額。。。。。。實在解決不了亂碼問題再考慮。。。

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證高級PHP講師

reply all(3)
劉奇

Try adding startup parameters: -Dfile.encoding=utf-8

Based on your description, I guess it’s a problem with MessageConverter

大家講道理

Add this

<bean
        class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jsonMessageConverter" />
            </list>
        </property>
    </bean>

    <!-- Configure bean to convert JSON to POJO and vice versa -->
    <bean id="jsonMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    </bean>
阿神

It has been solved. Annotation-driven is not supported because the namespace definition file referenced by the xml header generated by idea itself is 3.0. Just change it to the latest one. In the end, the message-converter is reset through annotation-driven. Encoded properties.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template