搭建项目
项目资源
提取码 链接:https://pan.baidu.com/s/19jYIaFlzWdQLM3c6IHwEmQ
提取码:i84l
更高版本
gulimall-coupon 优惠券模块
gulimall-member 用户模块
gulimall-order 订单模块
gulimall-product 商品模块
gulimall-ware 仓储模块
码云人人开源
https://gitee.com/renrenio
renren-fast 后台管理模块
renren-generator 代码生成器
renren-fast-vue 前端项目
前端运行注意事项
安装python,nodejs版本14.17.1
整合mybatis
//引入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<!--mssql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
创建application.yml
#配置数据源
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/gulimall_pms
driver-class-name: com.mysql.jdbc.Driver
#配置扫描
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
@MapperScan(“com.atguigu.gulimall.product.dao”)
nacos配置
<properties>
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>
</properties>
<!--
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系
-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring.cloud.alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<--!引入依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
下载https://github.com/alibaba/nacos/releases
版本1.1.3
win启动nacos
D:\software\nacos-server-1.1.3\nacos\bin startup.cmd
linux启动
# 单机启动
sh startup.sh -m standalone
# 关闭nacos
sh shutdown.sh
applicaiton.yml配置
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: gulimall-coupon
远程调用 openFeign
引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
编写测试
第一步编写接口 告诉spring-cloud这个接口需要远程调用
package com.atguigu.gulimall.member.feign;
import com.atguigu.common.utils.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient("gulimall-coupon")//声明需要调用哪个nacos服务
public interface CouponFeignService {
@RequestMapping("coupon/coupon/member/list")
public R membercoupons();
}
第二步新建文件夹存放调用
第三步添加启动项
@EnableFeignClients(basePackages = "com.atguigu.gulimall.member.feign")
注入service就可以调用其他服务的接口
nacos配置管理
<!--配置管理-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
创建bootstrap.properties
spring.application.name=gulimall-coupon
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
配置列表添加
通过@RefreshScope
@Value(“${user.name}”)动态获取配置