@ -0,0 +1,69 @@
|
||||
package com.itmk.web.category.controller;
|
||||
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.itmk.utils.ResultUtils;
|
||||
import com.itmk.utils.ResultVo;
|
||||
import com.itmk.web.category.entity.CategoryPageParm;
|
||||
import com.itmk.web.category.entity.SysCategory;
|
||||
import com.itmk.web.category.service.SysCategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/category")
|
||||
public class SysCategoryController {
|
||||
|
||||
// 注入服务类
|
||||
@Autowired
|
||||
private SysCategoryService sysCategoryService;
|
||||
|
||||
// 新增菜品分类
|
||||
@PostMapping
|
||||
public ResultVo addCategory(@RequestBody SysCategory sysCategory){
|
||||
//单独检查菜品分类名称
|
||||
if(sysCategoryService.lambdaQuery()
|
||||
.eq(SysCategory::getCategoryName, sysCategory.getCategoryName())
|
||||
.exists()){
|
||||
return ResultUtils.error("菜品分类已存在!");
|
||||
}
|
||||
return sysCategoryService.save(sysCategory)
|
||||
? ResultUtils.success("新增菜品分类成功!", sysCategory)
|
||||
: ResultUtils.error("新增菜品分类失败!");
|
||||
|
||||
}
|
||||
|
||||
// 编辑菜品分类
|
||||
@PutMapping
|
||||
public ResultVo editCategory(@RequestBody SysCategory sysCategory){
|
||||
if(sysCategoryService.updateById(sysCategory)){
|
||||
return ResultUtils.success("编辑菜品分类成功!", sysCategory);
|
||||
}
|
||||
return ResultUtils.error("编辑菜品分类失败!");
|
||||
}
|
||||
|
||||
// 删除菜品分类
|
||||
@DeleteMapping("/{categoryId}")
|
||||
public ResultVo deleteCategory(@PathVariable Long categoryId){
|
||||
if(sysCategoryService.removeById(categoryId)){
|
||||
return ResultUtils.success("删除菜品分类成功!");
|
||||
}
|
||||
return ResultUtils.error("删除菜品分类失败!");
|
||||
}
|
||||
|
||||
// 列表查询
|
||||
// 列表查询需要分页
|
||||
@GetMapping("/list")
|
||||
public ResultVo getList(CategoryPageParm parm) {
|
||||
IPage<SysCategory> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
|
||||
QueryWrapper<SysCategory> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().like(!StringUtils.isEmpty(parm.getCategoryName()), SysCategory::getCategoryName, parm.getCategoryName())
|
||||
.orderByAsc(SysCategory::getOrderNum);
|
||||
IPage<SysCategory> list = sysCategoryService.page(page, queryWrapper);
|
||||
return ResultUtils.success("查询成功", list);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.itmk.web.category.entity;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CategoryPageParm {
|
||||
private Integer currentPage;//当前页
|
||||
private Integer pageSize;//每页显示多少条
|
||||
private String categoryName;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.itmk.web.category.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
||||
@TableName("sys_category")//表明该类实体类所关联的数据表库
|
||||
|
||||
//创建一个实体类
|
||||
public class SysCategory {
|
||||
@TableId(type = IdType.AUTO) //表明这是一个主键,并且自动递增
|
||||
private Long categoryId;
|
||||
private String categoryName;
|
||||
private Integer orderNum;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.itmk.web.category.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.itmk.web.category.entity.SysCategory;
|
||||
|
||||
public interface SysCategoryMapper extends BaseMapper<SysCategory> {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.itmk.web.category.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.itmk.web.category.entity.SysCategory;
|
||||
|
||||
public interface SysCategoryService extends IService<SysCategory> {
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.itmk.web.category.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itmk.web.category.entity.SysCategory;
|
||||
import com.itmk.web.category.mapper.SysCategoryMapper;
|
||||
import com.itmk.web.category.service.SysCategoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCategory> implements SysCategoryService {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<!--xml接口映射文件-->
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.itmk.web.category.mapper.SysCategoryMapper">
|
||||
</mapper>
|
||||
@ -0,0 +1,17 @@
|
||||
// 定义数据类型
|
||||
|
||||
// 定义菜品列表查询的数据类型
|
||||
export type listCategoryParm = {
|
||||
currentPage: number;//当前页
|
||||
pageSize: number;//每页显示多少条
|
||||
categoryName: string;//根据菜品名查询
|
||||
total: number;//总条数
|
||||
}
|
||||
|
||||
// 定义菜品表单数据类型
|
||||
export type categoryModel = {
|
||||
categoryId: string;
|
||||
categoryName: string;
|
||||
orderNum: string;
|
||||
type: string;
|
||||
}
|
||||
@ -1,13 +1,59 @@
|
||||
<!-- 菜品分类的主界面 -->
|
||||
|
||||
<template>
|
||||
<div>
|
||||
菜品分类
|
||||
</div>
|
||||
<el-main>
|
||||
<!-- 搜索栏 -->
|
||||
<el-form :model="listParm" label-width="80px" :inline="true" size="default">
|
||||
<el-form-item>
|
||||
<!-- 通过v-model="listParm.categoryName"获取搜索框中输入的值 -->
|
||||
<el-input v-model="listParm.categoryName" placeholder="请输入菜品分类名称:"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="searchBtn" icon="Search">搜索</el-button>
|
||||
<el-button plain type="danger" @click="resetBtn" icon="Close">重置</el-button>
|
||||
<el-button plain type="primary" @click="addBtn" icon="Plus">新增</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 列表查询显示 -->
|
||||
<!-- 通过data属性绑定tableList获取存储在数据库中的值来执行列表查询 -->
|
||||
<el-table :height="tableHeight" :data="tableList" border stripe>
|
||||
<!-- label属性设置标题,prop属性绑定表格的数据类型 -->
|
||||
<el-table-column label="分类名称" prop="categoryName"></el-table-column>
|
||||
<el-table-column label="序号" prop="orderNum"></el-table-column>
|
||||
|
||||
<!-- 为表格添加编辑、删除按钮 -->
|
||||
<el-table-column label="操作" min-width="100" align="center">
|
||||
<template #default="scoped">
|
||||
<el-button type="primary" size="default" @click="editBtn(scoped.row)" icon="Edit">
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button type="danger" size="default" @click="deleteBtn(scoped.row)" icon="Delete">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 为表格添加分页显示 -->
|
||||
<el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page.sync="listParm.currentPage"
|
||||
:page-sizes="[10, 20, 40, 80, 100]" :page-size="listParm.pageSize"
|
||||
layout="total, sizes, prev, pager, next, jumper" :total="listParm.total" background>
|
||||
</el-pagination>
|
||||
|
||||
|
||||
<AddCategory ref="showBtn" @onFresh="getList"></AddCategory>
|
||||
</el-main>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import useCategoryTable from '@/compositions/category/useCategoryTable';
|
||||
const { tableList, tableHeight, listParm, getList, searchBtn, resetBtn, sizeChange, currentChange } = useCategoryTable()
|
||||
|
||||
</script>
|
||||
import useCategory from '@/compositions/category/useCategory';
|
||||
const { showBtn, addBtn, deleteBtn, editBtn } = useCategory(getList)
|
||||
|
||||
<style scoped>
|
||||
// 引入子组件AddCategory
|
||||
import AddCategory from './AddCategory.vue';
|
||||
</script>
|
||||
|
||||
</style>
|
||||
<style scoped></style>
|
||||
Loading…
Reference in new issue