xml層
<select id="getRecords" parameterType="java.util.HashMap" resultType="com.dongzhengafc.common.entity.approval.ApprovalRecordsEntity">
select * from table1
<where>
<if test="start!=null and start!=''">
and insert_day >= #{start}
</if>
<if test="end!=null and end!=''">
and insert_day <= #{end}
</if>
</where>
</select>
dao層
public interface ApprovalRecordsDao extends BaseMapper<ApprovalRecordsEntity> {
List<ApprovalRecordsEntity> getRecords(Pagination page, Map<String, Object> map);
}
Service層
public interface ApprovalRecordsService extends IService<ApprovalRecordsEntity> {
PageUtils queryPage(Map<String, Object> params);
}
Impl層
@Service("approvalRecordsService")
public class ApprovalRecordsServiceImpl extends ServiceImpl<ApprovalRecordsDao, ApprovalRecordsEntity> implements ApprovalRecordsService {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@Override
public PageUtils queryPage(Map<String, Object> params) {
String start = (String)params.get("start");
String end = (String)params.get("end");
//當前頁
int page = Integer.parseInt((String)params.get("page"));
//每頁size
int size = Integer.parseInt((String)params.get("limit"));
if(StringUtils.isBlank(start)&&StringUtils.isBlank(end)) {
start = sdf.format(new Date());
end = sdf.format(new Date());
}
params.put("start", start);
params.put("end", end);
Page<ApprovalRecordsEntity> result = new Page<ApprovalRecordsEntity>(page, size,"insert_time", false);
result.setRecords(this.baseMapper.getRecords(result, params));
return new PageUtils(result);
}
}