菜品分页查询
This commit is contained in:
parent
ed298ec39b
commit
af53702e96
|
@ -1,15 +1,14 @@
|
|||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -34,4 +33,12 @@ public class DishController {
|
|||
dishService.saveWithFlavor(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation("菜品分页查询")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult> pageResultResult(DishPageQueryDTO dishPageQueryDTO) {
|
||||
log.info("菜品分页查询:{}", dishPageQueryDTO);
|
||||
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
|
@ -24,4 +27,11 @@ public interface DishMapper {
|
|||
*/
|
||||
@AutoFill(value = OperationType.INSERT)
|
||||
void insert(Dish dish);
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return Page<DishVO>
|
||||
*/
|
||||
Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
public interface DishService {
|
||||
/**
|
||||
|
@ -9,4 +11,11 @@ public interface DishService {
|
|||
* @param dishDTO DishDTO
|
||||
*/
|
||||
void saveWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -46,4 +51,16 @@ public class DishServiceImpl implements DishService {
|
|||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
|
||||
PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
|
||||
Page<DishVO> page = dishMapper.pageQuery(dishPageQueryDTO);
|
||||
return new PageResult(page.getTotal(),page.getResult());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,23 @@
|
|||
from dish
|
||||
where category_id = #{categoryId}
|
||||
</select>
|
||||
|
||||
<!-- 菜品分页查询 -->
|
||||
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||
select d.*, c.name as categoryName
|
||||
from dish d
|
||||
left OUTER join category c on d.category_id = c.id
|
||||
<where>
|
||||
<if test="name != null">
|
||||
and d.name like concat("%",#{name},"%")
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and d.category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and d.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue