day(22) Echarts和nacos

一、Echarts和nacos

1.1 数据展示

  • 定时任务统计每一天的数据存储到数据表中
  • 前台展示时查询数据表,绘成相应的图表

1.2 查询日期之间的数据

  • between语句包含左边但是不包含右边
 SELECT * FROM edu_teacher WHERE gmt_create BETWEEN "2018-04-03" AND "2018-04-04"

二、配置中心

2.1 配置中心spring cloud config

2.1.1 缺点

  • 不能实时刷新配置文件
  • 没有图形界面

2.1.2 其他配置中心

  • apollo
  • nacos

2.2 nacos

2.2.1 pom

2.2.2 配置文件

  • bootstrap.yml先加载
  • application.yml后加载,所以会覆盖bootstrap.yml已经配置的设置
spring:
  application:
    name: service-sms
  profiles:
    active: dev # 环境标识,test、prod等
  cloud:
    nacos:
      config:
        server-addr: 127.0.0.1:8848 #nacos中心地址
        file-extension: yaml # 配置文件格式,如果是properties文件则不用配置此项
        namespace: fa8ee614-4504-4807-8e51-d2fe8fb9d20d
        group: 51
        ext-config:
        - data-id: aliyun.yaml
          group: 51
          refresh: true
        - data-id: redis.yaml
          group: 51
          refresh: true

2.2.3 Data id是微服务名称

在这里插入图片描述

  • dev环境下的Data id配置
    service-name-dev.yaml

2.2.4 优先级

  • nacos配置中心有限本地配置。

2.2.5 动态刷新

@RefreshScope

package com.atguigu.guli.service.sms.controller;

import com.atguigu.guli.common.base.result.R;
import com.atguigu.guli.service.sms.util.SmsProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author helen
 * @since 2020/5/9
 */
@RestController
@RequestMapping("/sms/sample")
@RefreshScope
public class SampleController {
    
    

    @Autowired
    private SmsProperties smsProperties;

    @Autowired
    private RedisTemplate redisTemplate;

    @Value("${aliyun.sms.signName}")
    private String signName;

    @GetMapping("test-sing-name")
    public R testSingName(){
    
    
        return R.ok().data("signName", signName);
    }

    @GetMapping("test-sms-properties")
    public R testSmsProperties(){
    
    
        return R.ok().data("smsProperties", smsProperties);
    }

    @GetMapping("test-redis")
    public R testRedis(){
    
    
        redisTemplate.opsForValue().set("test", "123", 5, TimeUnit.MINUTES);
        return R.ok();
    }
}

2.2.6 namespace

spring:
  cloud:
    nacos:
      config:
        namespace: fa8ee614-4504-4807-8e51-d2fe8fb9d20d

2.2.7 多配置文件

  • 添加配置
spring:
   cloud:
    nacos:
      config:
				- data-id: redis.yaml
				          group: 51
				          refresh: true

猜你喜欢

转载自blog.csdn.net/qq_42306803/article/details/129278689