可以使用Java的IO流来获取根目录mapper文件夹下所有properties文件,具体实现如下:

  1. 首先定义一个方法,输入参数为文件夹路径,返回值为所有properties文件的文件名列表:
public static List<String> getPropertiesFiles(String folderPath) {
    List<String> fileList = new ArrayList<>();
    File folder = new File(folderPath);
    File[] files = folder.listFiles();
    for (File file : files) {
        if (file.isFile() && file.getName().endsWith(".properties")) {
            fileList.add(file.getName());
        } else if (file.isDirectory()) {
            fileList.addAll(getPropertiesFiles(file.getAbsolutePath()));
        }
    }
    return fileList;
}
  1. 调用该方法获取根目录mapper文件夹下所有properties文件的文件名列表:
List<String> fileList = getPropertiesFiles("mapper");

注意:这里假设mapper文件夹在工程根目录下。如果不在根目录下,需要修改文件夹路径

java获取根目录mapper文件夹下所有properties文件怎么写

原文地址: https://www.cveoy.top/t/topic/fGnr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录