分页查询
This commit is contained in:
parent
e9bdc8baeb
commit
ac4e7d8108
|
@ -1,15 +1,14 @@
|
||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.SetmealService;
|
import com.sky.service.SetmealService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@ -33,4 +32,17 @@ public class SetmealController {
|
||||||
setmealService.saveWithDish(setmealDTO);
|
setmealService.saveWithDish(setmealDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO 请求参数
|
||||||
|
* @return 返回数据
|
||||||
|
*/
|
||||||
|
@ApiOperation("分页查询")
|
||||||
|
@GetMapping("page")
|
||||||
|
public Result<PageResult> pageResultResult(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||||
|
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
import com.sky.annotation.AutoFill;
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.entity.SetmealDish;
|
import com.sky.entity.SetmealDish;
|
||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -41,4 +44,12 @@ public interface SetMealDishMapper {
|
||||||
* @param setmealDishes List<SetmealDish>
|
* @param setmealDishes List<SetmealDish>
|
||||||
*/
|
*/
|
||||||
void insertBatch(List<SetmealDish> setmealDishes);
|
void insertBatch(List<SetmealDish> setmealDishes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||||
|
* @return Page<SetmealVO>
|
||||||
|
*/
|
||||||
|
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,4 +33,12 @@ public interface SetmealService {
|
||||||
* @param setmealDTO SetmealDTO
|
* @param setmealDTO SetmealDTO
|
||||||
*/
|
*/
|
||||||
void saveWithDish(SetmealDTO setmealDTO);
|
void saveWithDish(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.entity.SetmealDish;
|
import com.sky.entity.SetmealDish;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
import com.sky.mapper.SetMealDishMapper;
|
import com.sky.mapper.SetMealDishMapper;
|
||||||
import com.sky.mapper.SetmealMapper;
|
import com.sky.mapper.SetmealMapper;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.service.SetmealService;
|
import com.sky.service.SetmealService;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -70,4 +75,20 @@ public class SetmealServiceImpl implements SetmealService {
|
||||||
// 保存套餐和菜品的关联关系
|
// 保存套餐和菜品的关联关系
|
||||||
setmealDishMapper.insertBatch(setmealDishes);
|
setmealDishMapper.insertBatch(setmealDishes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||||
|
int pageNum = setmealPageQueryDTO.getPage();
|
||||||
|
int pageSize = setmealPageQueryDTO.getPageSize();
|
||||||
|
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
Page<SetmealVO> page = setmealDishMapper.pageQuery(setmealPageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,28 @@
|
||||||
left join dish d on sd.dish_id = d.id
|
left join dish d on sd.dish_id = d.id
|
||||||
where sd.setmeal_id = #{setmealId}
|
where sd.setmeal_id = #{setmealId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 分页查询 -->
|
||||||
|
<select id="pageQuery" resultType="com.sky.vo.SetmealVO">
|
||||||
|
select
|
||||||
|
s.*,c.name categoryName
|
||||||
|
from
|
||||||
|
setmeal s
|
||||||
|
left join
|
||||||
|
category c
|
||||||
|
on
|
||||||
|
s.category_id = c.id
|
||||||
|
<where>
|
||||||
|
<if test="name != null">
|
||||||
|
and s.name like concat('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and s.status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
and s.category_id = #{categoryId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by s.create_time desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue