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

完成新增菜品分类

前言



1、前期准备

定义实体类和实体对象

java 复制代码
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;

}
java 复制代码
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> {
}
java 复制代码
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 {
}
java 复制代码
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和时间

java 复制代码
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 分钟前
MySQL InnoDB 缓存池(Buffer Pool)详解:原理、结构与链表管理
java·数据结构·数据库·mysql·链表·缓存·面试
前端付豪2 分钟前
实现必要的流式输出(Streaming)
前端·后端·agent
heze092 分钟前
sqli-labs-Less-50
数据库·mysql·网络安全
go4it6 分钟前
Java26的新特性
后端
gechunlian889 分钟前
redis exporter手册
数据库·redis·缓存
2401_8534482313 分钟前
Maix例程代码学习
学习
木易 士心21 分钟前
深入理解 MySQL 权限撤销(REVOKE)机制:从语法到安全实践
数据库·后端·mysql·安全
yhole22 分钟前
Spring Boot整合Redisson的两种方式
java·spring boot·后端
FPGA小迷弟22 分钟前
FPGA工程师面试题汇总(二)
学习·fpga开发·verilog·fpga
sthnyph24 分钟前
Spring Boot 集成 Kettle
java·spring boot·后端