From 00a53ded358bde6715c498575b7b575142de75e8 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Sun, 8 Jan 2023 10:53:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=95=86=E5=93=81=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++ springcloud-service-goods/pom.xml | 2 +- .../com/kwan/springcloud/CommonConstant.java | 16 +++ .../java/com/kwan/springcloud/Result.java | 118 ++++++++++++++++++ .../controller/KwanGoodsInfoController.java | 86 +++++++++++++ .../springcloud/dao/KwanGoodsInfoDao.java | 17 +++ .../springcloud/entity/KwanGoodsInfo.java | 55 ++++++++ .../service/KwanGoodsInfoService.java | 16 +++ .../impl/KwanGoodsInfoServiceImpl.java | 19 +++ 9 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/CommonConstant.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/Result.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java create mode 100644 springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java diff --git a/pom.xml b/pom.xml index 907d0e7..60de534 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,10 @@ UTF-8 + + springcloud-service-goods + + @@ -36,4 +40,7 @@ + + pom + \ No newline at end of file diff --git a/springcloud-service-goods/pom.xml b/springcloud-service-goods/pom.xml index cc32e19..2a20a39 100644 --- a/springcloud-service-goods/pom.xml +++ b/springcloud-service-goods/pom.xml @@ -38,7 +38,7 @@ com.baomidou mybatis-plus-extension - 3.5.1 + 3.5.2 diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/CommonConstant.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/CommonConstant.java new file mode 100644 index 0000000..f4ceb31 --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/CommonConstant.java @@ -0,0 +1,16 @@ +package com.kwan.springcloud; + +public class CommonConstant { + /** + * 成功 + */ + public static final Integer SC_OK_200 = 200; + /** + * 服务器错误 + */ + public static final Integer SC_INTERNAL_SERVER_ERROR_500 = 500; + /** + * 未认证 + */ + public static final int SC_JEECG_NO_AUTHZ = 401; +} \ No newline at end of file diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/Result.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/Result.java new file mode 100644 index 0000000..fe971cc --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/Result.java @@ -0,0 +1,118 @@ +package com.kwan.springcloud; + +import java.io.Serializable; + +import lombok.Data; + +/** + * 接口返回数据格式 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/1/8 10:48 + */ +@Data +public class Result implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 成功标志 + */ + private boolean success = true; + /** + * 返回处理消息 + */ + private String message = "操作成功!"; + /** + * 返回代码 + */ + private Integer code = 0; + /** + * 返回数据对象 data + */ + private T result; + /** + * 时间戳 + */ + private long timestamp = System.currentTimeMillis(); + + public Result() { + } + + public Result success(String message) { + this.message = message; + this.code = CommonConstant.SC_OK_200; + this.success = true; + return this; + } + + public Result good(T t) { + this.setResult(t); + this.code = CommonConstant.SC_OK_200; + this.success = true; + return this; + } + + public Result good() { + this.code = CommonConstant.SC_OK_200; + this.success = true; + this.setMessage("成功"); + return this; + } + + public Result fail(String msg) { + this.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500); + this.setMessage(msg); + this.setSuccess(false); + return this; + } + + public static Result ok() { + Result r = new Result<>(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setMessage("成功"); + return r; + } + + public static Result ok(String msg) { + Result r = new Result(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setMessage(msg); + return r; + } + + public static Result ok(Object data) { + Result r = new Result(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setResult(data); + return r; + } + + public static Result error(String msg) { + return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); + } + + public static Result error(int code, String msg) { + Result r = new Result(); + r.setCode(code); + r.setMessage(msg); + r.setSuccess(false); + return r; + } + + public Result error500(String message) { + this.message = message; + this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; + this.success = false; + return this; + } + + /** + * 无权限访问返回结果 + */ + public static Result noauth(String msg) { + return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg); + } +} \ No newline at end of file diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java new file mode 100644 index 0000000..893f424 --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java @@ -0,0 +1,86 @@ +package com.kwan.springcloud.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kwan.springcloud.Result; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.List; + +/** + * (KwanGoodsInfo)表控制层 + * + * @author makejava + * @since 2023-01-08 10:21:26 + */ +@RestController +@RequestMapping("kwanGoodsInfo") +public class KwanGoodsInfoController { + /** + * 服务对象 + */ + @Resource + private KwanGoodsInfoService kwanGoodsInfoService; + + /** + * 分页查询所有数据 + * + * @param page 分页对象 + * @param kwanGoodsInfo 查询实体 + * @return 所有数据 + */ + @GetMapping + public Result selectAll(Page page, KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.page(page, new QueryWrapper<>(kwanGoodsInfo))); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + public Result selectOne(@PathVariable Serializable id) { + return Result.ok(this.kwanGoodsInfoService.getById(id)); + } + + /** + * 新增数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 新增结果 + */ + @PostMapping + public Result insert(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.save(kwanGoodsInfo)); + } + + /** + * 修改数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 修改结果 + */ + @PutMapping + public Result update(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.updateById(kwanGoodsInfo)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @DeleteMapping + public Result delete(@RequestParam("idList") List idList) { + return Result.ok(this.kwanGoodsInfoService.removeByIds(idList)); + } +} + diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java new file mode 100644 index 0000000..bd34f72 --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java @@ -0,0 +1,17 @@ +package com.kwan.springcloud.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import org.apache.ibatis.annotations.Mapper; + +/** + * (KwanGoodsInfo)表数据库访问层 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +@Mapper +public interface KwanGoodsInfoDao extends BaseMapper { + +} + diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java new file mode 100644 index 0000000..eee4643 --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java @@ -0,0 +1,55 @@ +package com.kwan.springcloud.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; + +import java.io.Serializable; + +/** + * (KwanGoodsInfo)表实体类 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +public class KwanGoodsInfo extends Model { + + private Integer id; + //商品名称 + private String goodsName; + //商品价格 + private Integer goodsPrice; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public Integer getGoodsPrice() { + return goodsPrice; + } + + public void setGoodsPrice(Integer goodsPrice) { + this.goodsPrice = goodsPrice; + } + + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + public Serializable pkVal() { + return this.id; + } +} diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java new file mode 100644 index 0000000..1913635 --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java @@ -0,0 +1,16 @@ +package com.kwan.springcloud.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springcloud.entity.KwanGoodsInfo; + +/** + * (KwanGoodsInfo)表服务接口 + * + * @author makejava + * @since 2023-01-08 10:21:29 + */ +public interface KwanGoodsInfoService extends IService { + +} + diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java new file mode 100644 index 0000000..6c6739d --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.kwan.springcloud.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springcloud.dao.KwanGoodsInfoDao; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.stereotype.Service; + +/** + * (KwanGoodsInfo)表服务实现类 + * + * @author makejava + * @since 2023-01-08 10:21:30 + */ +@Service("kwanGoodsInfoService") +public class KwanGoodsInfoServiceImpl extends ServiceImpl implements KwanGoodsInfoService { + +} + -- GitLab