diff --git a/pom.xml b/pom.xml index 907d0e76ad27687fd061f19c1c6239a4cf4afd75..60de534f7e851b677bd42e491143343ec344306d 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 cc32e19c7588ceba7c312fae162f12fe50fe8ec4..2a20a39b806340be2429081babfecf50e7c93294 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 0000000000000000000000000000000000000000..f4ceb315c764f45cc16fc4595b7ba1c8c2d7feed --- /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 0000000000000000000000000000000000000000..fe971cc72ec80487267be8cf50275b1d3510e3ad --- /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 0000000000000000000000000000000000000000..893f424c795ba99cdbddc6c46e1c96c46b8603ad --- /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 0000000000000000000000000000000000000000..bd34f72faed81c7bed2c395003e67f774047bfa4 --- /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 0000000000000000000000000000000000000000..eee4643dce4337c3d00271081f4758143812b7c5 --- /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 0000000000000000000000000000000000000000..1913635860d117d59e975fd39e2c9d3632e6f59f --- /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 0000000000000000000000000000000000000000..6c6739dab24b2812ff1751d6d79479f3e075f7f3 --- /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 { + +} +