瑞吉外卖实战学习--10、完成新增菜品分类

前言

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1、前期准备

在这里插入图片描述

定义实体类和实体对象

在这里插入图片描述

package com.example.ruiji_demo.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 分类
 * @author jitwxs
 * @date 2024年04月01日 21:30
 */
@Data
public class Category {
    private  static final long serialVersionUID=1L;

    private Long id;
//    类型: 1、菜品分类 2、套餐分类
    private Integer type;

//    分类名称
    private String name;

//    顺序
    private Integer sort;

//    创建时间
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

//    修改时间
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

//    创建用户
    @TableField(fill = FieldFill.INSERT)
    private Long createUser;

//    修改用户
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateUser;

}

在这里插入图片描述

package com.example.ruiji_demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.ruiji_demo.entity.Category;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
}

在这里插入图片描述

package com.example.ruiji_demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ruiji_demo.entity.Category;
import com.example.ruiji_demo.mapper.CategoryMapper;
import com.example.ruiji_demo.service.CategoryService;
import org.springframework.stereotype.Service;

/**
 * @author jitwxs
 * @date 2024年04月01日 21:44
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
}

在这里插入图片描述

package com.example.ruiji_demo.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.ruiji_demo.entity.Category;

public interface CategoryService extends IService<Category> {
}

2、创建修改的接口

由于我们之前写过字段自动补全添加修改和创建的id和时间
在这里插入图片描述

在这里插入图片描述

package com.example.ruiji_demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.ruiji_demo.common.R;
import com.example.ruiji_demo.entity.Category;
import com.example.ruiji_demo.service.CategoryService;
import jakarta.servlet.http.HttpServletRequest;
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 java.time.LocalDateTime;

/**
 * @author jitwxs
 * @date 2024年04月01日 21:53
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

//  注册创建的接口实体类
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public R<String> CreateCp(HttpServletRequest request, @RequestBody Category category){
//        获取用户id
        categoryService.save(category);

        return R.success("添加成功");
    }
}

在这里插入图片描述

在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-02 12:56:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-02 12:56:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-02 12:56:02       82 阅读
  4. Python语言-面向对象

    2024-04-02 12:56:02       91 阅读

热门阅读

  1. UDP端口连不上的情况

    2024-04-02 12:56:02       37 阅读
  2. Mybatis——SqlSession的工作流程

    2024-04-02 12:56:02       34 阅读
  3. 数据类型与变量

    2024-04-02 12:56:02       39 阅读
  4. php获取拼多多详情api接口、商品主图

    2024-04-02 12:56:02       34 阅读
  5. C++ 类

    C++ 类

    2024-04-02 12:56:02      33 阅读
  6. 摄像头读取数据

    2024-04-02 12:56:02       36 阅读
  7. SpringMVC上下文对象

    2024-04-02 12:56:02       31 阅读
  8. Git 的基本概念和使用方式

    2024-04-02 12:56:02       35 阅读