提交 00a53ded 编写于 作者: Q qinyingjie

fix:商品模块

上级 49985fa8
......@@ -24,6 +24,10 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>springcloud-service-goods</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
......@@ -36,4 +40,7 @@
</dependencies>
</dependencyManagement>
<packaging>pom</packaging>
</project>
\ No newline at end of file
......@@ -38,7 +38,7 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
</dependency>
<!--简化代码的工具包-->
<dependency>
......
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
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<T> 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<T> success(String message) {
this.message = message;
this.code = CommonConstant.SC_OK_200;
this.success = true;
return this;
}
public Result<T> good(T t) {
this.setResult(t);
this.code = CommonConstant.SC_OK_200;
this.success = true;
return this;
}
public Result<T> good() {
this.code = CommonConstant.SC_OK_200;
this.success = true;
this.setMessage("成功");
return this;
}
public Result<T> fail(String msg) {
this.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500);
this.setMessage(msg);
this.setSuccess(false);
return this;
}
public static Result<Object> ok() {
Result<Object> r = new Result<>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage("成功");
return r;
}
public static Result<Object> ok(String msg) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg);
return r;
}
public static Result<Object> ok(Object data) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setResult(data);
return r;
}
public static Result<Object> error(String msg) {
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
}
public static Result<Object> error(int code, String msg) {
Result<Object> r = new Result<Object>();
r.setCode(code);
r.setMessage(msg);
r.setSuccess(false);
return r;
}
public Result<T> error500(String message) {
this.message = message;
this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
this.success = false;
return this;
}
/**
* 无权限访问返回结果
*/
public static Result<Object> noauth(String msg) {
return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
}
}
\ No newline at end of file
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<KwanGoodsInfo> 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<Long> idList) {
return Result.ok(this.kwanGoodsInfoService.removeByIds(idList));
}
}
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<KwanGoodsInfo> {
}
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<KwanGoodsInfo> {
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;
}
}
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<KwanGoodsInfo> {
}
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<KwanGoodsInfoDao, KwanGoodsInfo> implements KwanGoodsInfoService {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册