目录
菜品新增
分析:
后台系统中可以管理菜品信息,通过 新增功能来添加一个新的菜品,在添加菜品时需要选择当前菜品所属的菜品分类,并且需要上传菜品图片,在移动端会按照菜品分类来展示对应的菜品信息 。
新增菜品,其实就是将新增页面录入的菜品信息插入到dish表,如果添加了口味做法,还需要向dish_flavor表插入数据。所以在新增菜品时,涉及到两个表:
菜品代码准备:
1.entity
package com.itheima.reggie.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 菜品
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class Dish implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 菜品的id
*/
private Long id;
/**
* 菜品名称
*/
@ApiModelProperty("菜品名称")
private String name;
/**
* 菜品分类id 就是套餐分类/菜品分类的id
*/
@ApiModelProperty("菜品分类id")
private Long categoryId;
/**
* 菜品价格
*/
@ApiModelProperty("菜品价格")
private BigDecimal price;
/**
* 商品码
*/
@ApiModelProperty("商品码")
private String code;
/**
* 图片
*/
@ApiModelProperty("图片")
private String image;
/**
* 描述信息
*/
@ApiModelProperty("描述信息")
private String description;
/**
* 菜品状态:0 停售 1 起售
*/
@ApiModelProperty("菜品状态:0 停售 1 起售")
private Integer status;
/**
* 顺序
*/
@ApiModelProperty("顺序")
private Integer sort;
/**
* 创建时间
*/
@ApiModelProperty("创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@ApiModelProperty("更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人姓名
*/
@ApiModelProperty("创建人姓名")
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 更新人姓名
*/
@ApiModelProperty("更新人姓名")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}
2.mapper
package com.itheima.reggie.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface DishMapper extends BaseMapper<Dish> {
}
3.service
package com.itheima.reggie.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.reggie.entity.Dish;
public interface DishService extends IService<Dish> {
}
4.sevice目录下的impl目录
package com.itheima.reggie.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.mapper.DishMapper;
import com.itheima.reggie.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class DishServiceImpl extends ServiceImpl<DishMapper,Dish> implements DishService {
}
5.controller
package com.itheima.reggie.controller;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
/**
* 菜品管理
*/
@RestController
@RequestMapping("/dish")
@Slf4j
@RequiredArgsConstructor //简化 @Autowired ,不用一个一个写
@Api(tags = "菜品管理接口")
public class DishController {
}
菜品口味代码准备:
1.entity
package com.itheima.reggie.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 菜品口味
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class DishFlavor implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 菜品口味id
*/
private Long id;
/**
* 菜品id
*/
@ApiModelProperty("菜品id")
private Long dishId;
/**
* 口味名称
*/
@ApiModelProperty("口味名称")
private String name;
/**
* 口味数据list
*/
@ApiModelProperty("口味数据list")
private String value;
/**
* 创建时间
*/
@ApiModelProperty("创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@ApiModelProperty("更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人姓名
*/
@ApiModelProperty("创建人姓名")
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 更新人姓名
*/
@ApiModelProperty("更新人姓名")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
@ApiModelProperty("是否删除")
private Integer isDeleted;
}
2.mapper
package com.itheima.reggie.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.entity.DishFlavor;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface DishFlavorMapper extends BaseMapper<DishFlavor> {
}
3.service
package com.itheima.reggie.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.reggie.entity.DishFlavor;
public interface DishFlavorService extends IService<DishFlavor> {
}
4.sevice目录下的impl目录
package com.itheima.reggie.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishFlavorMapper;
import com.itheima.reggie.service.DishFlavorService;
import org.springframework.stereotype.Service;
@Service
public class DishFlavorServiceImpl extends ServiceImpl<DishFlavorMapper,DishFlavor> implements DishFlavorService {
}