• springmvc:设置后端响应给前端的json数据转换成String格式


     设置spring-mvc.xml:

    '''xml

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:context="http://www.springframework.org/schema/context"
    4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    6. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    7. ">
    8. <context:component-scan base-package="com.ekgc.controller"/>
    9. <bean id="stringConverter"
    10. class="org.springframework.http.converter.StringHttpMessageConverter">
    11. <property name="writeAcceptCharset" value="false" />
    12. <property name="supportedMediaTypes">
    13. <list>
    14. <value>text/html;charset=UTF-8value>
    15. list>
    16. property>
    17. bean>
    18. <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
    19. <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    20. <property name="messageConverters">
    21. <list>
    22. <ref bean="stringConverter" />
    23. <ref bean="jsonConverter" />
    24. list>
    25. property>
    26. bean>
    27. beans>

    '''

    web.xml读取spring-mvc.xml

    '''xml

    1. web-app PUBLIC
    2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
    4. <web-app>
    5. <context-param>
    6. <param-name>contextConfigLocationparam-name>
    7. <param-value>classpath:spring-config.xmlparam-value>
    8. context-param>
    9. <listener>
    10. <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    11. listener>
    12. <servlet>
    13. <servlet-name>springMVCservlet-name>
    14. <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    15. <init-param>
    16. <param-name>contextConfigLocationparam-name>
    17. <param-value>classpath:spring-mvc.xmlparam-value>
    18. init-param>
    19. servlet>
    20. <servlet-mapping>
    21. <servlet-name>springMVCservlet-name>
    22. <url-pattern>/url-pattern>
    23. servlet-mapping>
    24. web-app>

    '''

  • 相关阅读:
    unity-多线程异步下载HttpWebRequest
    Web前端系列技术之Web APIs基础(从基础开始)②
    ElasticSearch7.3学习(二十八)----聚合实战之电视案例
    前端发送复杂JSON数据,后端接收方式
    【Linux operation 42】Linux 系统的时间
    Python每日一练 01
    [react性能优化]--防止react-re-render: Why Suspense and how ?
    L82.linux命令每日一练 -- 第11章 Linux系统管理命令 -- dmidecode和lspci
    数论专题(3)逆元
    Monkey命令
  • 原文地址:https://blog.csdn.net/qq_58647634/article/details/132635374