- mapper类
@Mapper
public interface RoomStatusDao extends BaseMapper<RoomStatusEntity> {
IPage<RoomStatusEntity> queryRoomStatusList(IPage<RoomStatusEntity> page, @Param(Constants.WRAPPER) Wrapper<RoomStatusEntity> queryWrapper, @Param("date") Date date);
}
- xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xx.xxx.modules.app.dao.RoomStatusDao">
<select id="queryRoomStatusList" resultType="xx.xxx.modules.app.entity.RoomStatusEntity">
SELECT ifnull(t2.id, -1) as id, t1.id as croom_info_id, croom_id, croom_name, status FROM (
select id, croom_id, croom_name from croom_info ${ew.customSqlSegment}) as t1
LEFT JOIN (
select id, croom_info_id, status from croom_date_status where date(date) = #{date}) as t2
ON t1.id = croom_info_id
</select>
</mapper>
- ServiceImpl类
@Override
public PageUtils queryRoomStatusList(Map<String, Object> params) {
int pageNum = params.get("page")==null?1:Integer.valueOf(params.get("page").toString());
int limitNum = params.get("page")==null?10:Integer.valueOf(params.get("limit").toString());
String croomId = (String)params.get("room");
Date date = params.get("date")==null||params.get("date").toString()==""?DateUtils.stringToDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()), DateUtils.DATE_PATTERN):DateUtils.stringToDate(params.get("date").toString(), DateUtils.DATE_PATTERN);
QueryWrapper<RoomStatusEntity> wrapper = new QueryWrapper<RoomStatusEntity>()
.eq( "croom_status", 0)
.like(StringUtils.isNotBlank(croomId),"croom_name", croomId)
.or()
.eq(!(croomId == null || "".equals(croomId)),"croom_id", croomId);
Page<RoomStatusEntity> page = new Page<>(pageNum, limitNum);
IPage<RoomStatusEntity> iPage = baseMapper.queryRoomStatusList(page, wrapper, date);
return new PageUtils(iPage);
}
目前mybatis-plus好像不支持在一个sql中用2个条件构造器。