程序员的资源宝库

网站首页 > gitee 正文

谷粒商城(谷粒平台)

sanyeah 2024-04-06 14:23:41 gitee 4 ℃ 0 评论

谷粒商城

p0-p14

本地环境:乌班图,docker,mysql本地,idea.git,node环境,jdk1.8

docker安装环境参考:https://www.cnblogs.com/q1359720840/p/14998691.html

p15 环境-数据库初始化

文件下载:https://player3.lanzouc.com/ifgQ616t68wd

创建好对应数据库,然后开始创建项目。

1.先弄pom项目

2.创建model

p16、快速开发-人人开源搭建后台管理系统

代码生成器

https://gitee.com/renrenio/renren-security

人人开源后端代码

https://gitee.com/renrenio/renren-fast

人人开源前端代码

https://gitee.com/renrenio/renren-fast-vue

配置人人开源后端代码修改dev.yml,数据库信息

这里默认的ip是8080端口

开启人人开源 前端代码

npm install 

npm run dev

默认启动地址是:localhost:8001

如果安装启动不成功可以尝试这个:

配置nvm。nvm use 10.16.3     地址:https://www.cnblogs.com/q1359720840/p/17282184.html

p17、快速开发-逆向工程搭建&使用

使用步骤:1.下载人人的代码生成器,这个是前后端都在一起的,默认80端口,修改数据库为你要生成的代码就行。generator.properties是你需要配置的包信息

导入后发现有的没有,所以需要修改相关vm文件

需要注意的是导出的文件里面有个
	private Longblob rollbackInfo;
识别不出来,改成这个
private byte[] rollbackInfo;

P18-19、快速开发-配置&测试微服务基本CRUD功能

    <!--        mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>
        
   <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.17</version>
        </dependency>

application.yml

配置数据库相关,auto为主键自增

spring:
  datasource:
    username: xx
    password: xx
    url: jdbc:mysql://ip:3306/gulimall_pms
    driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto

启动类配置扫描dao

@EnableDiscoveryClient
@MapperScan("com.player3.eshop.product.dao")
@SpringBootApplication
public class EshopProductApplication {

    public static void main(String[] args) {
        SpringApplication.run(EshopProductApplication.class, args);
    }

}

dao增加接口的继承

@Mapper
public interface PmsAttrAttrgroupRelationDao extends BaseMapper<PmsAttrAttrgroupRelationEntity> {
	
}

bean增加表相关配置

@Data
@TableName("pms_attr_attrgroup_relation")
public class PmsAttrAttrgroupRelationEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * id
	 */
	@TableId
	private Long id;
	/**
	 * 属性id
	 */
	private Long attrId;
	/**
	 * 属性分组id
	 */
	private Long attrGroupId;
	/**
	 * 属性组内排序
	 */
	private Integer attrSort;

}

p20-22. nacos集成以及分布式组件-SpringCloud-OpenFeign测试远程调用.

nacos      https://www.cnblogs.com/q1359720840/p/13524772.html

openfeign远程调用步骤

1.已经集成nacos
2.编写需要访问的基本信息。
比如:10001的服务eshop-coupon 开放给其他服务。自己和调用方都需要导入依赖,自己正常编写接口controller
      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
3.调用10001服务的10002,需要配置自己调用的接口包位置,这个是自己项目的包,如果没有需要创建,启动后会扫描这个包。


@EnableFeignClients(basePackages = "com.player3.eshop.member.feign")
@EnableDiscoveryClient
@SpringBootApplication
public class EshopMemberApplication {

    public static void main(String[] args) {
        SpringApplication.run(EshopMemberApplication.class, args);
        System.out.println("启动成功!");
    }

}

4.在这个包下创建对应需要扫描的位置,上面是服务名称,mapping那块是调用地址。
@FeignClient("eshop-coupon")
public interface SmsSeckillPromotionService {

    @RequestMapping("coupon/smsseckillpromotion/list")
    public R list(@RequestParam Map<String, Object> params);

    }
    
    
 5.配置好之后就可以正常调用   
    @RestController
@RequestMapping("eshop/index")
public class IndexController {

    @Autowired
    private SmsSeckillPromotionService smsSeckillPromotionService;
    @RequestMapping("/list")
     public R list(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("das","dsad");
        return smsSeckillPromotionService.list(map);

    }
}

p23、分布式组件-SpringCloud Alibaba-Nacos配置中心-简单示例

 * 1、如何使用Nacos作为配置中心统一管理配置
 *
 * 1)、引入依赖,
 *         <dependency>
 *             <groupId>com.alibaba.cloud</groupId>
 *             <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
 *         </dependency>
 * 2)、创建一个bootstrap.properties。
 *   spring.application.name=eshop-coupon
	spring.cloud.nacos.config.server-addr=127.0.0.1:8848
 * 3)、需要给配置中心默认添加一个叫 数据集(Data Id)eshop-coupon.properties。默认规则,应用名.properties
 * 4)、给 应用名.properties 添加任何配置
 * 5)、动态获取配置。
 *      @RefreshScope:动态获取并刷新配置
 *      @Value("${配置项的名}"):获取到配置。
 *      如果配置中心和当前应用的配置文件中都配置了相同的项,优先使用配置中心的配置。

24、分布式组件-SpringCloud Alibaba-Nacos配置中心-命名空间与配置分组

配置集和分组,根据不同环境,我们可以配置不同的配置集,比如dev,test,等等,namespace的值就是配置集里的id,命名空间下还可以设置不同分组,比如下面。配置集如果有多个分组可以指定分组,默认是DEFAULT_GROUP

spring.cloud.nacos.config.namespace=7952ce3d-1252-4790-bf56-1efb0aaf21ab
spring.cloud.nacos.config.group=DEFAULT_GROUP

25、分布式组件-SpringCloud Alibaba-Nacos配置中心-加载多配置集

bootstrap.properties 增加这个,可以将原来的配置拆分为多个小文件,默认走的是DEFAULT_GROUP分组,当配置中心没有的就用文件的,配置中心有的就用配置中心的。

spring.cloud.nacos.config.ext-config[0].data-id=datasource.yaml
spring.cloud.nacos.config.ext-config[0].group=DEFAULT_GROUP
spring.cloud.nacos.config.ext-config[0].refresh=true

spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yaml
spring.cloud.nacos.config.ext-config[1].group=DEFAULT_GROUP
spring.cloud.nacos.config.ext-config[1].refresh=true

26-27、分布式组件-SpringCloud-Gateway-集成与创建&测试API网关

p 26-27、分布式组件-SpringCloud-Gateway-创建&测试API网关

Description:

Parameter 0 of method loadBalancerWebClientBuilderBeanPostProcessor in org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration required a bean of type 'org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction' in your configuration.


Process finished with exit code 1

加了这个

  <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
            <version>3.0.2</version>
        </dependency>

继续报错:

ERROR 32247 --- [           main] c.a.cloud.nacos.NacosConfigProperties    : create config service error!properties=NacosConfigProperties{serverAddr='null', encode='null', group='DEFAULT_GROUP', prefix='null', fileExtension='properties', timeout=3000, endpoint='null', namespace='null', accessKey='null', secretKey='null', contextPath='null', clusterName='null', name='null', sharedDataids='null', refreshableDataids='null', extConfig=null},e=,

加了这个:

  <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
            <version>3.0.2</version>
        </dependency>

通过访问本机ip加:http://localhost:89/hello?url=cnblogs

spring:
  cloud:
    gateway:
      routes:
        - id: test_route
          uri: https://www.cnblogs.com/q1359720840/
          predicates:
            - Query=url,cnblogs

        - id: qq_route
          uri: https://www.qq.com
          predicates:
            - Query=url,qq

p28-35 es6

https://www.cnblogs.com/q1359720840/p/17593000.html

p36-43 vue部分

https://www.cnblogs.com/q1359720840/p/13913884.html

44、前端基础-Vue-整合ElementUI快速开发

npm install element-ui -S

// main.js
import Vue from 'vue';
import ElementUI from 'element-ui'; // 2.1引入结构
import 'element-ui/lib/theme-chalk/index.css'; // 2.2引入样式
import App from './App.vue';

Vue.use(ElementUI); // 3.安装

new Vue({
  el: '#app',
  render: h => h(App)
});

45-58、商品服务-API-三级分类

每个商品都属于一个类别,最左边是一级分类,中间的是二级分类,最右面是三级分类。
pms_category
分类id,分类名称,分类父id,分类层级,分类是否显示,图标,计量单位,当前分类下商品数量。

1.一次性查询出所有分类,以及子分类,以父子结构进行展示。

后端代码.

@RestController
@RequestMapping("product/pmscategory")
public class PmsCategoryController {
    @Autowired
    private PmsCategoryService pmsCategoryService;

    /**
     * 列表
     */
    @RequestMapping("/list/tree")
     public R list(){
         List<PmsCategoryEntity> list= pmsCategoryService.listWithTree();
    return R.ok().put("list", list);

    }
    @Override
    public List<PmsCategoryEntity> listWithTree() {
        List<PmsCategoryEntity> list = getBaseMapper().selectList(null);
        List<PmsCategoryEntity> collect = list.stream().filter(PmsCategoryEntity -> PmsCategoryEntity.getParentCid() == 0).map((menu) -> {
            menu.setChildren(getChildrens(menu, list));
            return menu;
        }).collect(Collectors.toList());

        return list;
    }
    private List<PmsCategoryEntity> getChildrens(PmsCategoryEntity root, List<PmsCategoryEntity> list) {
        List<PmsCategoryEntity> collect = list.stream()
                .filter((nemu) -> nemu.getParentCid().equals(root.getCatId())).
                map((Childrens) -> {
                    Childrens.setChildren(getChildrens(Childrens, list));
                    return Childrens;
                })
                .collect(Collectors.toList());

        return collect;
    }

前端

创建一个商品系统目录

创建出来之后/views/modules/product下的category.vue

将尚硅谷的前端代码贴进去。

发现需要运行8080端口,于是我们需要改一下。

renren-fast-vue/static/config文件目录下,有个index相关的js文件,修改
  window.SITE_CONFIG['baseUrl'] = 'http://localhost:89';
  

renrenfast需要更改的地方,由于我的项目里的renrenfast的admin没有集成nacos并且版本和其他的不一样,这个。

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.6.6</version>
	</parent>

需要导入这个版本的,这个怎么来的,我是找了maven的jar包搜索,发现这个和spring-boot-actuator 版本2.6.6最接近了。

<!--        服务注册/发现-->
		<dependency>
			<groupId>com.alibaba.cloud</groupId>
			<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
			<version>2021.0.4.0</version>
		</dependency>

只使用服务注册发现是可以的,如果想使用config的话,可能还需要做变动。

发现启动后报错:

http://localhost:89/captcha.jpg?uuid=e555c73f-25aa-47fd-824d-e5ef6b2a9b3b

以前是这个地址:

http://localhost:8080/renren-fast/captcha.jpg?uuid=7fb89dbe-6ca3-4193-879d-4ec177e768ad

把vue项目地址改成:

  window.SITE_CONFIG['baseUrl'] = 'http://localhost:89/api';

将前端项目都带api前缀,其他项目会访问到api/项目

spring:
  cloud:
    gateway:
      routes:      
      - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}

访问后出现503 跨域问题。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表