发布商品功能-打开会员功能
本章开始编写发布商品等相关功能,对应前端页面如下:
在这个发布商品功能中需要调用用户的会员等级接口,对应的API接口如下:
01、获取所有会员等级
POST
/member/memberlevel/list
请求参数
{
page: 1,//当前页码
limit: 10,//每页记录数
sidx: 'id',//排序字段
order: 'asc/desc',//排序方式
key: '华为'//检索关键字
}
分页数据
响应数据
{
"msg": "success",
"code": 0,
"page": {
"totalCount": 0,
"pageSize": 10,
"totalPage": 0,
"currPage": 1,
"list": [{
"id": 1,
"name": "aaa",
"growthPoint": null,
"defaultStatus": null,
"freeFreightPoint": null,
"commentGrowthPoint": null,
"priviledgeFreeFreight": null,
"priviledgeMemberPrice": null,
"priviledgeBirthday": null,
"note": null
}]
}
}
首先配置好会员服务连接到nacos注册中心的信息:
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://47.99.247.20:3306/mall_ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: mall-member
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
server:
port: 8000
之后配置网关在mall-gateway/src/main/resources/application.yml:
#会员服务
- id: member_route
uri: lb://mall-member
predicates:
- Path=/api/member/**
filters:
- RewritePath=/api/(?<segment>.*),/$\{segment}
之后重启服务即可正确刷新出会员界面,并添加会员:
由于会员服务比较简单,不需要过多的额外修改接口,所以使用与数据库绑定的逆向生成代码即可。