Mybatis自带的selectByExample修改查询条件

@Override
	public Page listAttendRecordByPage(AttendRecordDto recordDto) {
		PageHelper.startPage(recordDto.getPage(), recordDto.getLimit());
		Example example = new Example(TbAttendRecord.class);
		Criteria criteria = example.createCriteria();
		criteria.andCondition("work_date>="+recordDto.getStartDate());
		criteria.andCondition("work_date<="+recordDto.getEndDate());
		if(recordDto.getName() != null && !"".equals(recordDto.getName())){
			criteria.andCondition("name like '%"+recordDto.getName()+"%'");
		}
		if(recordDto.getEmpType() != null){
			criteria.andCondition("emp_type="+recordDto.getEmpType());
		}
		if(recordDto.getDeptId() != null){
			criteria.andCondition("dept_id="+recordDto.getDeptId());
		}
		Page list = (Page) recordMapper.selectByExample(example);
		Page convertList = BeanUtils.convertPage(list, AttendRecordDto.class);
		return convertList;
	}

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