parent
c1dde1f636
commit
85dcb59c62
@ -0,0 +1,61 @@
|
|||||||
|
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.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/category")
|
||||||
|
public class SysCategoryController {
|
||||||
|
|
||||||
|
// 注入服务类
|
||||||
|
private SysCategoryService sysCategoryService;
|
||||||
|
|
||||||
|
// 新增菜品
|
||||||
|
@PostMapping
|
||||||
|
public ResultVo addCategory(@RequestBody SysCategory sysCategory){
|
||||||
|
if(sysCategoryService.save(sysCategory)){
|
||||||
|
return ResultUtils.success("新增菜品成功!", sysCategory);
|
||||||
|
}
|
||||||
|
return 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>
|
Loading…
Reference in new issue