苍穹外卖--菜品管理-分页查询功能实现
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
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.beans.factory.annotation.Autowired;
|
||||
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.*;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@@ -30,4 +29,15 @@ public class DishController {
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("菜品分页查询")
|
||||
public Result<PageResult> page(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.Options;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
@@ -24,4 +27,11 @@ public interface DishMapper {
|
||||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Dish dish);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Page<DishVO> pageQuery(DishPageQueryDTO dto);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
public interface DishService {
|
||||
/*
|
||||
新增菜品和它的口味
|
||||
*/
|
||||
void saveDishWitchFlavor(DishDTO dto);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param dishPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
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 org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -46,4 +51,16 @@ public class DishServiceImpl implements DishService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(DishPageQueryDTO dto) {
|
||||
PageHelper.startPage(dto.getPage(), dto.getPageSize());
|
||||
Page<DishVO> page = dishMapper.pageQuery(dto);
|
||||
return new PageResult(page.getTotal(),page.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,20 @@
|
||||
insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status)
|
||||
values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
|
||||
</insert>
|
||||
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||
SELECT d.*,c.name categoryName FROM dish d LEFT JOIN category c ON d.category_id = c.id
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user