I am implementing a way to send a map to Spring Controller via ajax.
However, when I receive the map data from the controller, I receive the map data that contains nothing.
Map.size = 0...
Help me.
deduction: function (tr) {
var tr = $('tr[name=resultTable]');
var data = new Map();
for (var index = 0, size = tr.length; index < size; ++index) {
var td = tr.eq(index).children();
if (td.eq(1) === "COLOR") continue;
data.set(td.eq(5).text(), td.eq(3).text());
}
$.ajax({
type: 'PUT',
url: '/api/v1/stock/deduction',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data)
}).done(function () {
alert('ok');
window.location.reload();
}).fail(function () {
alert(JSON.stringify(error));
});
}
@PutMapping("/api/v1/stock/deduction")
public Long stockDeduction (@RequestBody Map<String, String> deductionMap) {
System.out.println(deductionMap.size());
return 1L;
}
We have confirmed that the map data to be transmitted has been correctly entered.