小编Kap*_*pil的帖子

如何拆分 application.properties 中的属性值

我想拆分 application.properties 定义的属性值并将其用作另一个属性的值。

以下是我在 application.properties 文件中的属性

test.product.release.version=2003.1
test.product.release.year=${test.product.release.version}.split('.')[0]
Run Code Online (Sandbox Code Playgroud)

我希望财产价值test.product.release.year2003

我尝试使用 split 来分割,${test.product.release.version}.split('.')[0]但是当我在控制器中获取该属性时,我仍然获得如下值2003.1.split('.')[0]

我怎样才能将其作为2003唯一?

spring spring-boot application.properties

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

遍历json对象以将根打印到由点分隔的子路径

所以直接解决问题。我有一些 json 对象,如下所示。

{
"root": {
    "Child": {
        "subChild": 10,
        "subChild2": 20
    },
    "Child2": {
        "subChild2": 20,
        "subChild3": 500
    }
}
Run Code Online (Sandbox Code Playgroud)

}

我想打印输出,如:

[root.Child.subChild,
root.Child.subChild2],

[root.Child2.subChild2,
root.Child2.subChild3]
Run Code Online (Sandbox Code Playgroud)

json 对象可以有多个嵌套级别。

python json

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

如何按实例计算方法调用

我有以下代码.

public interface Animal{

    void eat();
}

public class Lion implements Animal{

    @Override
    public void eat() {
        System.out.println("Lion can eat");
    }
    public static void main(String[] args) {

        Animal lion = new Lion();
        lion.eat();
        lion.eat();
        lion.eat();
    }
}
Run Code Online (Sandbox Code Playgroud)

你可以看到我打eat()三次电话.如何计算它被调用的次数?

请注意,您无法eat()从类中修改方法Lion

java oop

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

HashMap 以 String[] 作为值:需要数组,但 java.lang.Object

我正在调用一个单独的类方法,该方法将返回一个带有字符串数组作为值的哈希图。从方法内部,这些值可以作为数组访问,但是当返回到调用类方法时,它“变成”一个对象并生成错误:

需要数组,但找到了 java.lang.Object

调用方法:

public HashMap getBranches(){
    HashMap branches = dbMgr.getBranches();
    branches.forEach( (index, branch) -> {
      System.out.println(branch[0]); // This generates the error.
    });
    return(branches);
  }
Run Code Online (Sandbox Code Playgroud)

返回hashmap的方法:

HashMap branches = new HashMap<String, String[]>();
public HashMap getBranches(){

    System.out.println("\n[>] Getting branches...\n");
    DataFormatter formatter = new DataFormatter();
    Sheet sheet = tables.get("tbl_library_branch").getSheetAt(0);
    Iterator rowIter = sheet.rowIterator();

    while( rowIter.hasNext() ) {

      Row row = (Row) rowIter.next();
      Iterator cellIter = row.cellIterator();

      while(cellIter.hasNext()){
          String primaryKey = formatter.formatCellValue( (Cell) cellIter.next());
          String name = formatter.formatCellValue( (Cell) cellIter.next());
          String address = …
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×2

application.properties ×1

json ×1

oop ×1

python ×1

spring ×1

spring-boot ×1