小编Dra*_*wka的帖子

application.properties中的spring boot .env变量

我已经创建了 .env 文件,我现在在其中保存变量,我希望它们在我的 application.properties 中定义,但这不起作用。我需要添加什么来获取变量。

.env 文件

MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=root
Run Code Online (Sandbox Code Playgroud)

应用程序属性

spring.profiles.active = dev
Run Code Online (Sandbox Code Playgroud)

应用程序-dev.properties

# mysql database properties
spring.datasource.url = jdbc:mysql://localhost:3306/testdb?useUnicode=true&serverTimezone=UTC&server&createDatabaseIfNotExist=true
spring.datasource.username = ${MYSQLDB_USER}
spring.datasource.password = ${MYSQLDB_ROOT_PASSWORD}
        
# hibernate properties
spring.jpa.hibernate.ddl-auto = create
spring.jpa.show-sql = true
Run Code Online (Sandbox Code Playgroud)

environment-variables pom.xml maven spring-boot application.properties

4
推荐指数
1
解决办法
9085
查看次数

特定范围内的随机数

我想显示随机数特定范围[from, to]。以下代码写出该值,但某些内容无法正常工作:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int draw(int from_to, int to_from)
{
    return (rand()%to_from)+from_to;
}
int main()
{
    srand(time(NULL));
    int start,stop;
    cout << "First number: " << endl;
    cin >> start;
    cout << "Last number: " << endl;
    cin >> stop;
    int x=20;
    do
    {
        cout << draw(start,stop) << endl;
        x--;
    } while(x>0);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ random

-2
推荐指数
1
解决办法
114
查看次数