当前位置: 首页 > news >正文

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

 设置spring-mvc.xml:

'''xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
"><!--将bean交给dispatcherServlet使用--><context:component-scan base-package="com.ekgc.controller"/><!--    设置后端响应给前端的json数据转换成String格式--><bean id="stringConverter"class="org.springframework.http.converter.StringHttpMessageConverter"><property name="writeAcceptCharset" value="false" /><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></bean><bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/><bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"><property name="messageConverters"><list><ref bean="stringConverter" /><ref bean="jsonConverter" /></list></property></bean>
</beans>

'''

web.xml读取spring-mvc.xml

'''xml

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-config.xml</param-value></context-param><!-- 监听spring容器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>springMVC</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

'''

http://www.lryc.cn/news/151137.html

相关文章:

  • Mac安装brew、mysql、redis
  • MLC-LLM 部署RWKV World系列模型实战(3B模型Mac M2解码可达26tokens/s)
  • Unity 之 参数类型之值类型参数的用法
  • VScode远程连接主机
  • 【iOS】属性关键字
  • 【计算机基础】Git从安装到使用,详细每一步!扩展Github\Gitlab
  • 深入了解Docker镜像操作
  • 嵌入式开发-单片机学习介绍
  • 5、Spring之Bean生命周期源码解析(销毁)
  • 开发多点触控MFC应用程序
  • 使用nlohmann json库进行序列化与反序列化
  • 高教社杯数模竞赛特辑论文篇-2012年A题:葡萄酒的评价(附获奖论文)
  • 手写RPC——数据序列化工具protobuf
  • 【MATLAB第70期】基于MATLAB的LightGbm(LGBM)梯度增强决策树多输入单输出回归预测及多分类预测模型(全网首发)
  • Linux进程间通信的几种方式
  • Android 13.0 Launcher3定制之双层改单层(去掉抽屉式一)
  • 【uniapp 配置启动页面隐私弹窗】
  • 2分钟讲清楚C#的委托, C语言的函数指针,Java的函数式接口
  • 华为云物联网平台微信小程序开发教程2.0【完整详细教程】
  • Laravel 模型1对1关联 1对多关联 多对多关联 ⑩①
  • 【分类】分类性能评价
  • M1 Pro 新芯片安装python2 方案汇总
  • 无涯教程-Android - Broadcast Receivers
  • 【Pytorch】Tutorials个人翻译集合
  • WordPress(6)网站侧边栏倒计时进度小工具
  • uniapp小程序单页面改变手机电量,头部通知的颜色效果demo(整理)
  • 数据挖掘导论学习笔记1(第1 、2章)
  • 从零开始,探索C语言中的字符串
  • Ubuntu学习---跟着绍发学linux课程记录(第二部分)
  • React18 新特性