首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >SpringBoot中的profile的使用

SpringBoot中的profile的使用

作者头像
GeekLiHua
发布2025-01-21 16:08:14
发布2025-01-21 16:08:14
13800
代码可运行
举报
文章被收录于专栏:JavaJava
运行总次数:0
代码可运行

SpringBoot中的profile的使用

简介:本文通过案例讲解SpringBoot中的profile的使用。

概述

profile是用来完成不同环境下的,配置的动态切换功能的。

配置方式

properties

这里是三种不同的properties文件,我们想要运行哪一个,可以在第一个application.properties文件中指定. application-dev.properties

application-pro.properties

application-test.properties

spring.profiles.active=test # 指定pro为前缀的properties为主要运行文件

yml

文件结构

学习代码

代码语言:javascript
代码运行次数:0
运行
复制
---
server:
  port: 8081

spring:
  profiles: div
---

server:
  port: 8082

spring:
  profiles: test
---

server:
  port: 8083

spring:
  profiles: pro
---
spring:
  profiles:
    active: pro

运行结果

程序打包运行

合并集合

一共有 n 个数,编号是 1∼n,最开始每个数各自在一个集合中。

现在要进行 m 个操作,操作共有两种:

M a b,将编号为 a 和 b 的两个数所在的集合合并,如果两个数已经在同一个集合中,则忽略这个操作; Q a b,询问编号为 a 和 b 的两个数是否在同一个集合中; 输入格式 第一行输入整数 n 和 m。

接下来 m 行,每行包含一个操作指令,指令为 M a b 或 Q a b 中的一种。

输出格式 对于每个询问指令 Q a b,都要输出一个结果,如果 a 和 b 在同一集合内,则输出 Yes,否则输出 No。

每个结果占一行。

数据范围 1≤n,m≤105 输入样例: 4 5 M 1 2 M 3 4 Q 1 2 Q 1 3 Q 3 4 输出样例: Yes No Yes

提交代码

代码语言:javascript
代码运行次数:0
运行
复制
#include<iostream>
using namespace std;

const int N = 100010;
int n, m;
int p[N];

int find(int x)                 // 找到x的祖先节点
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) p[i] = i;
    
    while (m--)
    {
        char op;
        int a, b;
        scanf (" %c%d%d", &op, &a, &b);
        if (op == 'M') p[p[find(a)]] = find(b);        // 让a的祖先节点指向b的祖先节点
        else
        {
            if (find(a) == find(b)) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}
代码语言:javascript
代码运行次数:0
运行
复制
import java.io.*;

public class Main
{
    static int N = 100010;
    static int n, m;
    static int [] p = new int [N];
    
    static int find(int x)
    {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }
    
    public static void main(String[] args) throws IOException
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader (System.in));   
        String [] str = reader.readLine().split(" ");
        n = Integer.parseInt(str[0]);
        m = Integer.parseInt(str[1]);
        
        for (int i = 1; i <= n; ++ i) p[i] = i;
        while (m -- > 0)
        {
            String op;
            int a, b;
            str = reader.readLine().split(" ");
            op = str[0];
            a = Integer.parseInt(str[1]);
            b = Integer.parseInt(str[2]);
            if (op.equals("M")) p[find(a)] = find(b);
            else 
            {
                if (find(a) == find(b)) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-12-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SpringBoot中的profile的使用
    • 概述
    • 配置方式
      • properties
      • yml
    • 程序打包运行
  • 合并集合
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档