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

前端特殊字符数据,后端接收产生错乱,前后端都需要处理

前端:

const data = {createTime: "2024-06-11 09:58:59",id: "1800346960914579456",merchantId: "1793930010750218240",mode: "DEPOSIT",channelCode: "if(amount >= 50){'iugu2pay';} else if(amount < 10){'iugupay';} else {'todaypay';}",settleRate: 8,settleFee: 8,conditionSettleRate: "if(amount >= 5){ 0.2;} else{0.88;}",name: "HaliAntpay"
};// Encode the fields
data.channelCode = encodeURIComponent(data.channelCode);
data.conditionSettleRate = encodeURIComponent(data.conditionSettleRate);// Send the encoded data
fetch('http://your-backend-endpoint/yourEndpoint', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.error('Error:', error));

后端:

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;@RestController
public class YourController {@PostMapping("/yourEndpoint")public AjaxResult yourMethod(@RequestBody String rawRequestBody) throws IOException {System.out.println("Received raw JSON: " + rawRequestBody);ObjectMapper mapper = new ObjectMapper();MerchantChnlSetting merchantChnlSetting = mapper.readValue(rawRequestBody, MerchantChnlSetting.class);// Decode the fieldsString decodedChannelCode = URLDecoder.decode(merchantChnlSetting.getChannelCode(), StandardCharsets.UTF_8.name());String decodedConditionSettleRate = URLDecoder.decode(merchantChnlSetting.getConditionSettleRate(), StandardCharsets.UTF_8.name());// Set the decoded values back to the objectmerchantChnlSetting.setChannelCode(decodedChannelCode);merchantChnlSetting.setConditionSettleRate(decodedConditionSettleRate);System.out.println("Mapped Object: " + merchantChnlSetting);// Continue processingreturn AjaxResult.success();}
}
http://www.lryc.cn/news/389022.html

相关文章:

  • 力扣热100 哈希
  • [图解]SysML和EA建模住宅安全系统-05-参数图
  • JavaScript——对象的创建
  • 大二暑假 + 大三上
  • C语言使用先序遍历创建二叉树
  • 如何在服务器中安装anaconda
  • 夸克网盘拉新暑期大涨价!官方授权渠道流程揭秘
  • 机器学习(三)
  • PostgreSQL 基本SQL语法(二)
  • linux 控制台非常好用的 PS1 设置
  • 【紫光同创盘古PGX-Nano教程】——(盘古PGX-Nano开发板/PG2L50H_MBG324第十二章)Wifi透传实验例程说明
  • 详述乙级资质企业在城市综合管廊与隧道一体化设计中的挑战与机遇
  • 如何借助物联网实现农情监测与预警
  • 一个项目学习Vue3---响应式基础
  • 白骑士的Python教学基础篇 1.5 数据结构
  • Go 常用文件操作
  • 大数据、人工智能、云计算、物联网、区块链序言【大数据导论】
  • ComfyUI流程图、文生图、图生图步骤教学!
  • CSS基础知识学习指南
  • 力扣hot100 -- 贪心算法
  • P2P文件传输协议介绍
  • Spring Boot集成Spring Mobile快速入门Demo
  • 走进开源企业 | 湖南大学OpenHarmony技术实训活动在开鸿智谷顺利举办!
  • TCP单进程循环服务器程序与单进程客户端程序
  • QT+winodow 代码适配调试总结(二)
  • 百家讲坛 | 裴伟伟:企业中安全团队应当如何反馈漏洞
  • 巧用Fiddler中的Comments提升接口测试效率
  • 停车场车牌识别计费系统,用Python如何实现?
  • Linux内核——Linux内核体系模式(二)
  • Spring MVC的高级功能——异常处理(一)简单异常处理器