easyUI带上传的表单提交

jsp页面 表单

<tr>
					<td><label>播放形式:</label></td>  
					<td><input name="pattern" type="radio" class="easyui-radiobox" value="0" id="radioLB"><span>轮播</span>    
						<input name="pattern" type="radio" class="easyui-radiobox" value="1" id="radioCB"><span>插播</span></td>
				</tr>
				<tr id="inputCB1" style="display: none">
					<td><label> 横版图片 </label></td>
					<td><input multiple style="width:300px" id="fileputHB" name="fileputHB" class="easyui-filebox" ></td>
				</tr>
				<tr id="inputCB2" style="display: none">
					<td><label> 竖版图片 </label></td>
					<td><input multiple style="width:300px" id="fileputSB" name="fileputSB" class="easyui-filebox" > </td>
				</tr>
				<tr id="inputCB3" style="display: none">
					<td><label> 背景音乐 </label></td>
					<td><input multiple  style="width:300px" id="fileputM" name="fileputM" class="easyui-filebox"></td>
				</tr>
				<tr id="inputLB" style="display: none">
					<td ><label for="form-field-2"> 轮播H5地址 </label></td>
					<td><input type="text"
						id="form-field-2" placeholder="输入URL地址" class="easyui-textbox" name="html" /></td>
				</tr>
				<tr align="center">
				
					<td><button type="button" οnclick="subFrom()" class="easyui-linkbutton">
						提交
					</button></td>
					     
					<td><button class="easyui-linkbutton" type="reset">
						重置
					</button></td>
				</tr>

当选择不同播放形式 radio时,出现不同的上传方式的js
<script>
	$(function() {
		$(":radio")
				.click(
						function() {
							if (this.click) {
								if ($(this).attr("id") == "radioLB") {
									document.getElementById('inputLB').style.paddingLeft = '280px';
									$('#inputLB').show();
									$('#inputCB1').hide();
									$('#inputCB2').hide();
									$('#inputCB3').hide();
								}
								if ($(this).attr("id") == "radioCB") {
									document.getElementById('inputCB1').style.paddingLeft = '255px';
									document.getElementById('inputCB2').style.paddingLeft = '255px';
									document.getElementById('inputCB3').style.paddingLeft = '255px';
									$('#inputCB1').show();
									$('#inputCB2').show();
									$('#inputCB3').show();
									$('#inputLB').hide();
								}
							}
						});
	});
</script>

提交的js

<!-- 提交表单 -->
<script>
	function subFrom() {
		var form = new FormData(document.getElementById("adverform1"));
		//var form = $("#adverForm1").serialize(); 
		form.append("userUuid", "123456");
		console.log(form.pattern);
		$.ajax({
			url : "${pub}/adverOrder/add",
			type : "post",
			data :form,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.info == 'success') {
					alert(data.msg);
				} else {
					alert(data.msg);
				}
			},
			error : function(e) {
				alert("出错了、请稍后重试!!");
			}
		});
	}
</script>

controller:

@ResponseBody
	@RequestMapping("/add")
	public JSONObject add(@RequestParam("fileputHB")MultipartFile fileHB,@RequestParam("fileputSB")MultipartFile fileSB,
			@RequestParam("fileputM")MultipartFile fileM,AdvertisingOrder adverOrder){
		JSONObject jo = new JSONObject();
		if(adverOrder.getPattern()==null){
			jo.put("info","fail");jo.put("msg","必填项不能为空");
			return jo;
		}
		switch (adverOrder.getPattern().toString()) {
		case "true":
			jo = adverOrderService.add(fileHB, fileSB, fileM, adverOrder);
			break;
		case "false":
			jo = adverOrderService.add(adverOrder);
			break;
		}
		System.out.println(jo);
		return jo;
	}

service的各层验证:
	@Override
	public JSONObject add(AdvertisingOrder adver) {
		JSONObject jo = new JSONObject();
		//数据验证
		if("".equals(adver.getAdvertistingName())||adver.getAdvertistingName()==null){
			jo.put("info", PromptMsgUtil.FAIL);
			jo.put("msg", PromptMsgUtil.NOT_NULL_MSG);
			return jo;
		}
		if("".equals(adver.getCommunityUuid())||adver.getCommunityUuid()==null){
			jo.put("info", PromptMsgUtil.FAIL);
			jo.put("msg", PromptMsgUtil.NOT_NULL_MSG);
			return jo;
		}
		if("".equals(adver.getHtml())||adver.getHtml()==null){
			jo.put("info", PromptMsgUtil.FAIL);
			jo.put("msg", PromptMsgUtil.NOT_NULL_MSG);
			return jo;
		}
		if("".equals(adver.getStartTime())||adver.getStartTime()==null
				||"".equals(adver.getEndTime())||adver.getEndTime()==null){
			jo.put("info", PromptMsgUtil.FAIL);
			jo.put("msg", PromptMsgUtil.NOT_NULL_MSG);
			return jo;
		}
		
		try {
			Date date1 = Helper.getHelp().DateFormat(adver.getStartTime());
			Date date2 = Helper.getHelp().DateFormat(adver.getEndTime());
			if(date1.getTime()>=date2.getTime()){
				jo.put("msg", PromptMsgUtil.START_THAN_END);
				jo.put("info", PromptMsgUtil.FAIL);
				return jo;
			}
		} catch (Exception e) {
			jo.put("msg", PromptMsgUtil.DATE_FORMAT);
			jo.put("info", PromptMsgUtil.FAIL);
			return jo;
		}
		
		List<AdvertisingOrder> select = advertisingOrderDao.selectByANameAndCID(adver.getCommunityUuid(), adver.getAdvertistingName());
		if(!select.isEmpty()){
			jo.put("info", PromptMsgUtil.FAIL);
			jo.put("msg", PromptMsgUtil.ORDER_NAME_REPEAT);
			return jo;
		}
		
		String orderNumber = Helper.getHelp().getOrderNumber();
		adver.setOrderNumber(orderNumber);
		adver.setCurrentState(0);
		adver.setDeleteFlag(false);
		
		advertisingOrderDao.insert(adver);
		jo.put("info", PromptMsgUtil.SUCCESS);
		jo.put("msg",PromptMsgUtil.ADD_SUCCESS);
		
		return jo;
	}
未完....前台提交的validate还正在写...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值