Java 多条数据提交,前台js如何传值,后台如何接参

     先上图,就类似一次性添加 多个商品

Java 多条数据提交,前台js如何传值,后台如何接参_第1张图片

 HTML

医嘱编码 药品名称 生产批号 数量 剂量 频率 用药途径 备注

 JS

function btnyizhu() {
			var hos_id = $("[name='hos_id']").val();
			var bed_id = $("[name='bed_id']").val();
			var patient_name = $("[name='patient_name']").val();
			var sex = $("[name='sex']").val();
			var age = $("[name='age']").val();
			var instro_doctor = $("[name='instro_doctor']").val();
			var instro_date = $("[name='instro_date']").val();
 
				var data = {
					hos_id : hos_id,
					bed_id : bed_id,
					patient_name : patient_name,
					sex : sex,
					age : age,
					instro_doctor : instro_doctor,
					instro_date : instro_date,
					instro_id : instro_id,
					drugs_name : drugs_name,
					pro_num : pro_num,
					quantity : quantity,
					dose : dose,
					freequency : freequency,
					method : method,
					remark : remark
				};
				$.ajax({
					url : "addYiZhu",
					dataType : "json",
					contentType : "application/json;charsetset=UTF-8",//必
					type : "post",
					cache : false,
					data: JSON.stringify(data),//必须
					success : function(obj) {
						if (obj == "400") {
							layer.alert('医嘱生成成功!', function(index) {
								window.location.reload();
							});
						} else if (obj == "404") {

							layer.alert("该药品库存不足!!!");
						} else {
							layer.alert("医嘱生成失败,请查看网络!!!");
						}
					},
					error : function(textStatus, e) {
						layer.alert("系统ajax交互错误: ");
					}
				});
			}

		}

 后台接受多个参数

Controller控制层
//提交医嘱
	@RequestMapping(value="addYiZhu",method=RequestMethod.POST, produces = {"application/json; charset=UTF-8"})
	@ResponseBody
	public String  addYiZhuOrder(@RequestBody JSONObject obj){
		return  drugService.addYiZhuOrder(obj);
	}

serviceImpl 业务层
@Override
	@Transactional
	public String addYiZhuOrder(JSONObject obj) {
		
		String hos_id = (String) obj.get("hos_id");
		String bed_id = (String) obj.get("bed_id");
		String patient_name = (String) obj.get("patient_name");
		String sex = (String) obj.get("sex");
		String age = (String) obj.get("age");
		String instro_doctor = (String) obj.get("instro_doctor");
		String instro_date = (String) obj.get("instro_date");
	     String instroNum = UUIDUtil.create();
		DrugsHead drugsHead = new DrugsHead();
		drugsHead.setHos_id(hos_id);
		drugsHead.setBed_id(bed_id);
		drugsHead.setPatient_name(patient_name);
		drugsHead.setSex(sex);
		drugsHead.setAge(age);
		drugsHead.setInstro_doctor(instro_doctor);
		drugsHead.setInstro_date(instro_date);
		drugsHead.setInstroNum(instroNum);
		boolean stu = mapper.addDrugAllOrder(drugsHead);
		if (stu==true) {
		JSONArray instro_id = obj.getJSONArray("instro_id");
		JSONArray drugs_name = obj.getJSONArray("drugs_name");
		JSONArray pro_num = obj.getJSONArray("pro_num");
		JSONArray quantity = obj.getJSONArray("quantity");
		JSONArray dose = obj.getJSONArray("dose");
		JSONArray freequency = obj.getJSONArray("freequency");
		JSONArray method = obj.getJSONArray("method");
		JSONArray remark = obj.getJSONArray("remark");
	     boolean status = false;
		Map map = new HashMap();
	
	     
	    for (int i = 0; i < instro_id.size(); i++) {
	    	 String instro_id0 = instro_id.getString(i);
 	    	 String drugs_name0 = drugs_name.getString(i);
	    	 String pro_num0 = pro_num.getString(i);
	    	 String quantity0 = quantity.getString(i);
	    	 String dose0 = dose.getString(i);
	    	 String freequency0 = freequency.getString(i);
	    	String method0 = method.getString(i);
	    	String remark0 = remark.getString(i);
	    	
	    	map.put("instroNum", instroNum);
	    	map.put("instro_id0", instro_id0);
			map.put("drugs_name0", drugs_name0);
			map.put("pro_num0", pro_num0);
			map.put("quantity0", quantity0);
			map.put("dose0", dose0);
			map.put("freequency0", freequency0);
			map.put("method0", method0);
			map.put("remark0", remark0);
			map.put("hos_id", hos_id);
			map.put("bed_id", bed_id);
			map.put("patient_name", patient_name);
			map.put("sex", sex);
			map.put("age", age);
			map.put("instro_doctor", instro_doctor);
			map.put("instro_date", instro_date);
			 Drug drug = mapper.queryDrug(pro_num0);
			 Integer inventory = drug.getInventory();
			 Integer quanit = Integer.valueOf(quantity0);  
			 if (quanit>inventory)
			     {	//库存不存
					 return "404"; 
				 }
				 else if(quanit<=inventory)
				 { 
				   Integer cha = (inventory - quanit);
				   boolean s = mapper.updateInventory(pro_num0,cha);
				   if (s==true) {
					 
				   }
				 }
	          status = mapper.addDrugOrder(map);
		    }
	    
	    if (status == true) {
			return "400";
	     	} 
		}
 		return "fail";
	}

OVER 是不是很简单啊,里面有些代码被我剪掉了,不影响大局。

Java 多条数据提交,前台js如何传值,后台如何接参_第2张图片

 

 

你可能感兴趣的:(java,js)