javascript - 使用 Spring Boot 将 JavaScript 对象的请求发布到 JSON
问题描述
我是编码新手,我正在使用带有 POST 请求的 Spring Boot 的 Crud Repository 保存单行数据,//但我想知道如何使用 Spring Boot 在单个 POST 请求中保存多行数据:
以下是我发送单行数据的过程:
// Declaring Variable for MySQL Table Column for getting html data into JavaScript
var data = {
billNo : "",
descriptions : "",
account : "",
amount : 0,
};
// Setting HTML Values into JavaScript
// I Used 'x' for multiple Rows for HTML document ID, 'x' is 0 for First Row, 1 for 2nd Row and go on.
data.billNo = document.getElementById("BillNo"+x).value;
data.descriptions = document.getElementById("Description"+x).value;
data.acount = document.getElementById("Account"+x).value;
data.amount = document.getElementById("Amount"+x).value;
// Converting JavaScript to JSON
var json = JSON.stringify(data);
//Sending POST Request : Every thing is OK if Single Row Data
HTTP('Post','/expenses',json).then(jsonData => {
//Start of Request Object
console.log(jsonData);
//End of Request Object
});
//HTTP Request Function
const HTTP = (method, url,JSON)=>{
const PROMISE = new Promise((resolve, reject) =>{
const XHRR = new XMLHttpRequest();
XHRR.open(method,url);
XHRR.responseType="json";
XHRR.setRequestHeader('Content-Type', 'application/json');
XHRR.onload = () => {
resolve(XHRR.response);
};
XHRR.send(JSON);
});
return PROMISE;
};
我可以使用 HTML 动态行,使用动态文档 ID。图片附在我的 HTML 屏幕上
我想知道如何为多行保存数据
解决方案
推荐阅读
- javascript - SVG 视图框可以在 HTML 画布内吗?
- python - 显示不同比例的重叠额外刻度和标签
- php - OAuth 是否允许 localhost 进行调试?
- c# - 是什么导致 ComboBox 显示 `System.Data.DataRowView`
- react-native - 在 expo init 上找不到模块
- git - 如何在 git 存储库上移动标签
- ruby - kv 插件:检查 value 是否为数组,并将 value 分配给新字段
- kubernetes - 如何从java app(k8s)收集日志到fluentd(k8s)
- java - 为什么我的测试junit cucumber测试在一起运行时失败,但单独通过,在第二次测试中抛出没有这样的ID会话?
- ios - 拖动时更改表格视图单元格背景颜色