欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

LayUI日历控件使用--如何向后台传值

程序员文章站 2022-04-08 09:34:06
...

上代码

1.html代码

<label class="layui-form-label">到期时间:</label>
				<div class="layui-input-inline">
					<input class="layui-input"  name="addDate1" id="rangeTime" placeholder="yyyy-MM-dd HH:mm:ss">
				</div>

2.js代码

//时间控件
	layui.use('laydate', function(){
		var laydate = layui.laydate;
		laydate.render({
		    elem: '#rangeTime'
			,type: 'datetime'
			,range: true
			,done: function(value, date, endDate){
				StartTime = data_string_layui(date);
				EndTime = data_string_layui(endDate);
			  }
			
		  });
		})

 /**
  * 日期转换--只针对layui
  * @param dateObj
  * @returns
  */
 function dateToStringForLayui(dateObj) {
		var FullYear = dateObj.year;
		var Month = dateObj.month;
		var Day = dateObj.date;
		var Hours = dateObj.hours;
		var Minutes = dateObj.minutes;
		var Seconds = dateObj.seconds;
	return FullYear+"-"+Month+"-"+Day+" "+Hours+":"+Minutes+":"+Seconds

}

3.后台java代码

@RequestMapping("searchWhiteList")
	public ModelAndView searchWhiteList(Integer curr,Integer limit, String expirationDateBeginStr, String expirationDateEndStr){
		
		if(StringUtil.isNotEmpty(expirationDateBeginStr)) {
			vehicleWhitelist.setExpirationDateBegin(DateTimeUtil.parse(expirationDateBeginStr, FORMAT_TYPE.DATE_TIME));
		}
		if(StringUtil.isNotEmpty(expirationDateEndStr)) {
		vehicleWhitelist.setExpirationDateEnd(DateTimeUtil.parse(expirationDateEndStr, FORMAT_TYPE.DATE_TIME));	
		}
		ModelAndView mv = new ModelAndView();
		mv.setView(Jackson2Util.jsonView());
		page=curr==null?1:curr;
		rows=limit==null?10:limit;
		// 使用PageHelper分页
		PageHelper.startPage(page, rows);
		List<VehicleWhitelist> vehicleWhiteList = null;		
		Page<VehicleWhitelist> page = (Page<VehicleWhitelist>)vehicleWhiteList;
		long total=page.getTotal();
		mv.addObject("count",total );
		mv.addObject("code", 0);
		mv.addObject("data", vehicleWhiteList);
		return mv;
	}

注意:layui从前端页面向后端Controller穿参数 都是String 类型格式 ,后台需要转换相应的类型使用

相关标签: LayUI