增删改查后台

master
niubi 2024-04-20 14:02:04 +08:00
parent 6749441c9d
commit 2f4aec76b2
4 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package com.eleadmin.common.system.controller;
import com.eleadmin.common.system.entity.Goods;
import com.eleadmin.common.system.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/goods")
public class GoodsController {
@Autowired
private GoodsService goodsService;
@GetMapping
public List<Goods> getAllGoods() {
return goodsService.list();
}
@GetMapping("/{id}")
public Goods getGoodsById(@PathVariable Long id) {
return goodsService.getById(id);
}
@PostMapping
public boolean createGoods(@RequestBody Goods goods) {
return goodsService.save(goods);
}
@PutMapping("/{id}")
public boolean updateGoods(@PathVariable Long id, @RequestBody Goods goods) {
goods.setId(id);
return goodsService.updateById(goods);
}
@DeleteMapping("/{id}")
public boolean deleteGoods(@PathVariable Long id) {
return goodsService.removeById(id);
}
}

View File

@ -0,0 +1,48 @@
package com.eleadmin.common.system.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(description = "商品")
@TableName("sys_goods")
public class Goods implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("主键id")
@TableId(type = IdType.AUTO)
private Long id;
@ApiModelProperty("商品编号")
private String goodsId;
@ApiModelProperty("商品标题")
private String title;
@ApiModelProperty("商品类型")
private String goodType;
@ApiModelProperty("价格")
private double price;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("创建者ID")
private String creatorId;
@ApiModelProperty("修改时间")
private Date changeDate;
@ApiModelProperty("修改者ID")
private String changorId;
}

View File

@ -0,0 +1,10 @@
package com.eleadmin.common.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eleadmin.common.system.entity.Goods;
import org.springframework.stereotype.Repository;
@Repository
public interface GoodsMapper extends BaseMapper<Goods> {
// 可以添加自定义的查询方法
}

View File

@ -0,0 +1,11 @@
package com.eleadmin.common.system.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eleadmin.common.system.entity.Goods;
import com.eleadmin.common.system.mapper.GoodsMapper;
import org.springframework.stereotype.Service;
@Service
public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {
// 这里可以编写额外的业务逻辑方法
}