day(22) Echarts和nacos
- 一、Echarts和nacos
 - 1.1 数据展示
 - 1.2 查询日期之间的数据
 
- 二、配置中心
 - 2.1 配置中心spring cloud config
 - 2.1.1 缺点
 - 2.1.2 其他配置中心
 
- 2.2 nacos
 - 2.2.1 pom
 - 2.2.2 配置文件
 - 2.2.3 Data id是微服务名称
 - 2.2.4 优先级
 - 2.2.5 动态刷新
 - 2.2.6 namespace
 - 2.2.7 多配置文件
 
一、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
                







![[busybox] busybox生成一个最精简rootfs(上)](https://img-blog.csdnimg.cn/f4d53ade7a26410793822d5b6fd6b14c.png)







![Mysql全解[基础篇]](https://img-blog.csdnimg.cn/066c4d9a092f4ebc8c80ce145c024fd4.png)

