模糊查询

今天我要分享的是我项目中的模糊查询,它是根据监督部门名称和时间段查询数据,它可以单个条件进行查询,也可以组合起来查询数据。

数据表格
在这里插入图片描述
通过名称进行筛选数据
在这里插入图片描述
通过名称和时间段进行筛选数据
在这里插入图片描述

首先是时间段的input标签,我用的是layui的插件,通过ID绑定标签,让它可以选择日期。

var createTimeS = laydate.render({
		elem : '#createTimeStart',
		type : 'datetime',
		max : nowTime,
		done : function(value, date) {
			endMax = createTimeE.config.max;
			createTimeE.config.min = date;````````
			createTimeE.config.min.month = date.month - 1;
		}
	});
elem是标签的ID名
type是类型,这里是datetime类型
max: nowTime是最大值为现在的时间,不能超出时间。

然后根据ID获取监督部门名称和开始时间与结束时间中的值,然后进行传参到controller控制器中。

active = {
			search : function(){
			var supervisiondepartmentsname = $('#mingcheng').val();
				var createTimeStart = $('#createTimeStart').val();
				var createTimeEnd = $('#createTimeEnd').val();
				
				layuiTable.reload('employee',{
					page : {
						curr : 1
					},
					where : {
						supervisiondepartmentsname : supervisiondepartmentsname,
						createTimeStart : createTimeStart,
						createTimeEnd : createTimeEnd,
					}
				});
			}
		};

传参到这个方法里面进行查询数据。

//查询数据
		@RequestMapping("selectSuper") 
		@ResponseBody
	  	public ResultUtil selectSuper(Integer page, Integer limit,SupervisionSearch Search){ 
		  ResultUtil admins = supervisiondepartmentService.selectSuper(page, limit,Search);
		  return admins;
		}

在ServiceImpl层中对数据进行分页处理,这里用的是PageHelper进行分页。
然后对数据进行筛选并查询出来。

@Override
	public ResultUtil selectSuper(Integer page, Integer limit,SupervisionSearch Search) {
		PageHelper.startPage(page,limit);
		List<Supervisiondepartments> Super=supervisiondepartmentsDAO.selectSuper(Search);
		PageInfo<Supervisiondepartments> pageInfo=new PageInfo<Supervisiondepartments>(Super);
		ResultUtil resultUtil = new ResultUtil();
		resultUtil.setCode(0);
		resultUtil.setCount(pageInfo.getTotal());
		resultUtil.setData(pageInfo.getList());
		return resultUtil;
	}

下面是查询方法中的sql语句,先查询出监督部门这个表。
如果监督部门名称不等于null and不是空的字符串就查询出监督部门名称中相对应的数据。
然后执行下面的if语句,如果开始时间与结束时间不等于null and 开始时间与结束时间不是空的字符串就查询出相关时间的数据。
这样,当我们选择时间进行筛选数据或者通过名称进行模糊查询就可以得到我们想要的数据了。

<select id="selectSuper" resultMap="BaseResultMap" parameterType="com.gx.po.Supervisiondepartments">
		select * from b_supervisiondepartments
		<where>
		1=1
			<if test="null != supervisiondepartmentsname and '' != supervisiondepartmentsname">
				and SupervisionDepartmentsName like "%"#{supervisiondepartmentsname}"%"
			</if>
			<if test="null != createTimeStart and null != createTimeEnd and '' != createTimeStart and '' != createTimeEnd">
				and RegistrationDate between #{createTimeStart} and #{createTimeEnd}
			</if>
			<if test="'' != createTimeStart and '' == createTimeEnd">
				and RegistrationDate between #{createTimeStart} and curtime()
			</if>
			<if test="'' == createTimeStart and '' != createTimeEnd">
				and RegistrationDate between '1900-01-01 00:00:00' and #{createTimeEnd}
			</if>
		</where>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值