• 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>

    '''

  • 相关阅读:
    学习笔记--LinearSVM#Hardmax/softmax
    P1165 日志分析
    牛客编程题--必刷101之双指针篇
    关于el-date-picker组件修改输入框以及下拉框的样式
    2.Asp.net Core使用Redis-StackExchange.Redis操作
    redis 通信协议(RESP),最简单的应用层协议,没有之一
    Apache ECharts简介和相关操作
    二叉查找树的插入
    ElasticSearch7.3学习(二十八)----聚合实战之电视案例
    Pytorch网络模型训练
  • 原文地址:https://blog.csdn.net/qq_58647634/article/details/132635374