前台代码:
var codes=new Array();
$(".bottlecode").each(function(){
codes.push($(this).val());
});
$.ajax({
type:"POST",
dataType:"json",
data:{
params:codes
},
url:"${ctx}/samplingmanage/preparationManage/ajaxEncode",
success:function(data){
var en=data.body.encodes;
for(var key in en){//遍历从后台获取的map对象
console.log("key:"+key);
console.log("value:"+en[key]);
}
}
});
后台代码:
@RequestMapping(value = "ajaxEncode", method=RequestMethod.POST)
@ResponseBody
public AjaxJson getEncode(@RequestParam(required = false, value = "params[]")List<String> params){
HashMap<String, String> map = new HashMap<String, String>();
AjaxJson ajaxJson=new AjaxJson();
for (String bottlecode : params) {
String replace = bottlecode.replace("_", "");
String encode = BarcodeUtils.generateBarCode128(replace,"0.5","30");
map.put(bottlecode, encode);
}
ajaxJson.put("encodes", map);
return ajaxJson;
}