【发布时间】:2016-03-31 15:40:32
【问题描述】:
大家好,请问如何获取我在 javascript 中创建的对象数组并发送到 spring 控制器。
$(table).find('tr').each(function(index) {
$this = $(this)
var value = $this.find("span.value").html();
var quantity = $this.find("input.quantity").val();
var lots = $this.find(".lots").val(), produits = $this
.find(".produits").val(), fournisseurs = $this
.find(".fournisseurs").val(), ref = $this
.find(".ref").html(), unite = $this
.find(".unite").val(), prix = $this
.find(".prix").html(), qte = $this
.find(".qte").val(), total = $this
.find(".total").text();
var ligne = new Object();
ligne.lot = lots;
ligne.produit = produits;
ligne.fournissuer = fournisseurs;
ligne.unite = unite;
ligne.prix = prix;
ligne.total = total;
ligne.ref = ref;
ligne.qte = qte;
tableau.push(ligne)
});
这是我的 Ajax 请求
$.ajax({
traditional : true,
async : false,
url : '/save/',
contentType : "application/json",
type : "POST",
data : JSON.stringify(tableau),
success : function(data) {
console.log("okk ");
},
error : function(jqXHR, textStatus, errorThrown) {
console.log('erreur');
}
还有 Spring 控制器。
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@RequestBody ArrayList<ChiffrageLigne> tableau) {
log.info("liste des donnees = "+tableau.size());
for (ChiffrageLigne chiffrageLigne : tableau) {
System.out.println("ref fournisseur"+chiffrageLigne.getRefFour()+"prix ="+chiffrageLigne.getPrix());
}
return "ok";
}
那么我如何在 sping mvc 控制器中获取这个数组。谢谢
【问题讨论】:
-
你能不能尝试通过
JSON.stringify(ligne);将此对象作为JSON发送到spring mvc。 -
我这样做了,但没有任何改变它给了我错误“NetworkError: 400 Mauvaise Requête - localhost:8080/project/requst”
标签: javascript list spring-mvc controller