3月23日

4260 ワード

左の右と同じ

右側にビューが指定されていない場合は、requestmapping値が検索されます.
@Model Ar TreviewはsetAttributeのキー値です.
買い物かごコウリャン片用Ajax.@ResponseBodyの活用JavaはJSONに送信できます.
GoodsController
@RequestMapping(value="/goodsCartUpdate", method=RequestMethod.GET)
	@ResponseBody
	public List<MemberDTO> goodsCartUpdate(@RequestParam HashMap<String, Integer> map) throws Exception {
		int n  = cService.cartUpdate(map);
		
		MemberDTO dto = new MemberDTO();
		dto.setUserid("aaa");
		dto.setUsername("홍길동");
		
		MemberDTO dto2 = new MemberDTO();
		dto2.setUserid("aaa2");
		dto2.setUsername("홍길동2");
		
		List<MemberDTO> list = Arrays.asList(dto,dto2);
		return list;
	}
cartList
function amountUpdate(num){
		httpRequest = new XMLHttpRequest();
		console.dir(httpRequest);
		
		//요청시 응답처리하는 함수 호출
		httpRequest.onreadystatechange=responseFun;

		
		global_num = num;
		var input_amount = document.querySelector("#cart_amount"+num);
		var amount = input_amount.value;
		var url = `goodsCartUpdate?num=\${num}&gAmount=\${amount}`;
		httpRequest.open("get",url,true);  
		httpRequest.send(null);  
	}	

	function responseFun(){
	    if(httpRequest.readyState==4 && httpRequest.status == 200){
	    	alert("갯수 수정 성공");
	    	/////////
	    	var mesg = httpRequest.responseText;
	    	console.log(">>"+mesg);
	    	var jsonObj = JSON.parse(mesg);
	    	console.log(jsonObj);
	    	////////
	    	var price = document.querySelector("#cart_price"+global_num).innerText;
	    	var amount = document.querySelector("#cart_amount"+global_num).value;
	        document.querySelector("#sum"+global_num).innerText = price * amount;
	    }
	}
これは追加されましたテキストとして受け取り、Jsonオブジェクトに変更して使用します.
var mesg = httpRequest.responseText;
	    	console.log(">>"+mesg);
	    	var jsonObj = JSON.parse(mesg);
	    	console.log(jsonObj);
orderDTO orderDTOは、値を受け入れながらモデルになるパラメータです.

1つのorderDTOパラメータがこんなに多く消えてしまった.
String userid = dto.getUserid();
				//상품정보
				String gCode = request.getParameter("gCode");
				String gName = request.getParameter("gName");
				String gPrice = request.getParameter("gPrice");
				String gSize = request.getParameter("gSize");
				String gColor = request.getParameter("gColor");
				String gAmount = request.getParameter("gAmount");
				String gImage = request.getParameter("gImage");
				//배송정보
				String orderName = request.getParameter("orderName");
				String post1 = request.getParameter("post1");
				String addr1 = request.getParameter("addr1");
				String addr2 = request.getParameter("addr2");
				String phone = request.getParameter("phone");
				//결제정보
				String payMethod = request.getParameter("payMethod");
				
				//cart에서 삭제할 num
				String cartNum = request.getParameter("cartNum");
				
				
				OrderDTO orderDTO = new OrderDTO();
				orderDTO.setUserid(userid);
				orderDTO.setgCode(gCode);
				orderDTO.setgName(gName);
				orderDTO.setgPrice(Integer.parseInt(gPrice));
				orderDTO.setgSize(gSize);
				orderDTO.setgColor(gColor);
				orderDTO.setgAmount(Integer.parseInt(gAmount));
				orderDTO.setgImage(gImage);
				orderDTO.setOrderName(orderName);
				orderDTO.setPost(post1);
				orderDTO.setAddr1(addr1);
				orderDTO.setAddr2(addr2);
				orderDTO.setPhone(phone);
				orderDTO.setPayMethod(payMethod);