小编Ari*_*car的帖子

如何使用Spring Boot从java属性文件中读取数据

我有一个spring启动应用程序,我想从我的application.properties文件中读取一些变量.事实上,下面的代码就是这样做 但我认为这种替代方案有一个很好的方法.

Properties prop = new Properties();
InputStream input = null;

try {
    input = new FileInputStream("config.properties");
    prop.load(input);
    gMapReportUrl = prop.getProperty("gMapReportUrl");
} catch (IOException ex) {
    ex.printStackTrace();
} finally {
    ...
}
Run Code Online (Sandbox Code Playgroud)

java properties spring-boot

21
推荐指数
3
解决办法
8万
查看次数

将Activiti任务从旧进程迁移到新进程

我有一个针对某些业务流程的Activiti项目.

问题在于迁移.现有流程有一些未完成的任务.我想通过添加新步骤来修改现有流程.

现在,当我创建一个新任务时,将根据更新的过程处理这个新任务.未完成的任务将根据旧流程进行处理.

我们来看以下示例:https://spring.io/blog/2015/03/08/getting-started-with-activiti-and-spring-boot

在此示例中,请考虑以下行:

taskVariables.put("telephoneInterviewOutcome", true);
Run Code Online (Sandbox Code Playgroud)

假设我有一些业务逻辑代码,我检查这个变量的值,如:

if (taskVariables.get("telephoneInterviewOutcome") == true) {...}
Run Code Online (Sandbox Code Playgroud)

现在假设,我想将此变量从Boolean修改为Enum.现在,我还需要更新我的业务逻辑:

if (taskVariables.get("telephoneInterviewOutcome") == SOMEENUM) {...}
Run Code Online (Sandbox Code Playgroud)

现在,我的业务逻辑代码需要根据手头任务的进程版本进行分支.如果任务属于进程的版本1,那么我将使用第一个语句,否则第二个类似于:

if (getProcessVersion(task) == 1) {
    if (taskVariables.get("telephoneInterviewOutcome") == true) {...}
} else {
    if (taskVariables.get("telephoneInterviewOutcome") == SOMEENUM) {...}
}
Run Code Online (Sandbox Code Playgroud)

这种方法的问题在于业务逻辑代码将随着流程的更新而增长.这会在生产过程中造成很多错误.

这个问题还有其他解决办法吗?如何在不更改业务逻辑代码的情况下解决此问题?

java workflow business-process-management bpmn activiti

6
推荐指数
2
解决办法
1767
查看次数

为什么Intellij默认的getter/setter模板删除我的布尔"是"变量名前缀?

我有一个实体.我将变量定义为boolean,并使用Intellij Idea Shortcuts创建了Getter和Setter方法.

private Boolean isForLaboratory = false;
Run Code Online (Sandbox Code Playgroud)

ddasd

在此输入图像描述

创建后它生成了这个:

public Boolean getForLaboratory() {
    return isForLaboratory;
}

public void setForLaboratory(Boolean forLaboratory) {
    isForLaboratory = forLaboratory;
}
Run Code Online (Sandbox Code Playgroud)

我期待getIsForLaboratory和setIsForLaboratory.它是Java的通用约定吗?为什么Intellij删除了我的前缀?

java coding-style intellij-idea

6
推荐指数
1
解决办法
1757
查看次数

Spring JPA:如何在不丢失数据的情况下进行upsert

如果不存在,是否有任何方法可以插入新记录并在不丢失旧数据的情况下更新记录?

这是我的服务层方法:

public void saveSample(Sample sample) {
    Sample samplePersistent = sample;

    if (sample.getId() != null) {
        samplePersistent = sampleRepository.findOne(sample.getId());
        Assert.notNull(samplePersistent, "Sample entity not found with id : " + sample.getId());

        samplePersistent.setLocation(sample.getLocation());
        samplePersistent.setName(sample.getName());
        samplePersistent.setType(sample.getType());
        ...
        ...

    }

    samplePersistent.cloneAuditingInfoFrom(sample);
    sampleRepository.save(sample);
}
Run Code Online (Sandbox Code Playgroud)

我认为这是无用的方式.

Spring BeanUtils Class或@DynamicUpdate Annotation可以解决我的问题吗?

java spring spring-mvc spring-data-jpa spring-boot

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