首页 > 解决方案 > 获取从 Thymeleaf 到控制器的文件路径

问题描述

我必须从 Excel 文件中获取一些数据,并且在尝试测试时我手动设置路径(它有效!)。
现在我想创建一个页面并使用按钮选择文件以获取路径。

这是我的控制器:

@RequestMapping(value = "/mypage")
public String fct(Model md) throws Exception{
    File excel=new File("pathofmyfile/name.xls");//here the path
    FileInputStream fis= new FileInputStream(excel);
    HSSFWorkbook wb=new HSSFWorkbook(fis);
    HSSFSheet ws=wb.getSheet("Feuil1");//to read first sheet only 

    int nbligne=ws.getLastRowNum()+1;//to get number of line not empty

    String[] cotes=new String[nbligne];

    for(int i =0;i<nbligne;i++) {
        HSSFRow ligne= ws.getRow(i);
        HSSFCell cell= ligne.getCell(0);
        cotes[i]= cell.toString().substring(cell.toString().lastIndexOf("=") + 1);

        System.out.println(cotes[i]);
    }

    return "mypage";
}

现在我想要你的建议或 html 页面的示例如何将 excel 的路径从 html 传递到控制器

标签: javaexcelspring-bootthymeleaf

解决方案


推荐阅读