瑞吉外卖实战学习--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("添加成功");
    }
}
相关推荐
cipher1 天前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全
毅航1 天前
自然语言处理发展史:从规则、统计到深度学习
人工智能·后端
JxWang051 天前
Task04:字符串
后端
树獭叔叔1 天前
10-让模型更小更聪明,学而不忘:知识蒸馏与持续学习
后端·aigc·openai
JxWang051 天前
Task02:链表
后端
只会cv的前端攻城狮1 天前
Elpis-Core — 融合 Koa 洋葱圈模型实现服务端引擎
前端·后端
codetown1 天前
2026年Zig编程语言权威指南:从系统级底层架构到现代软件工程实践
后端·程序员
cg331 天前
cc-connect,十分钟帮你把 claude code 连接到微信,飞书,钉钉等等平台
后端·openai
用户1427868669321 天前
Java多态的底层真相:JVM到底怎么知道该调哪个方法?(面试高频)
后端