【问题标题】:html list items trigger spring boot controllerhtml列表项触发spring boot控制器
【发布时间】:2018-05-27 13:12:51
【问题描述】:

我有一个下拉按钮,带有导出到 CSV 和导出到 excel 的选项。 当我点击每个选项时,我想触发相应的控制器方法来下载文件。

我的html代码如下:

<div class="row col-xs-2" style="position:relative;top:10px;">
                             <button type="button" class="btn btn-primary normal-btn dropdown-toggle" data-toggle="dropdown">
                             Export  <span class="caret"></span>
                             </button>
                             <ul class="dropdown-menu" role="menu">
                                <form action="#" data-th-action="@{/coaExport}" method="POST">
                                    <li><a type="submit" name="action" value="csv" id="coaExport_CS1V" class="dropdown-item" href="#">Export to .CSV</a></li>
                                    <li><a type="submit" name="action" value="excel" id="coaExport_exc1el" class="dropdown-item" href="#">Export to Excel</a></li>
                                </form>
                             </ul>
                          </div>'

我的控制器数据是:

    @GetMapping(value="/coaExport", params="action=csv")
    public void exportCOACSV(HttpServletRequest request,  HttpServletResponse response) throws IOException {
        System.out.println("Export CSV");
   }

    @GetMapping(value="/coaExport", params="action=excel")
    public void exportCOAExcel(HttpServletRequest request,  HttpServletResponse response) throws IOException {
        System.out.println("Export Excel.");
}

【问题讨论】:

  • 您拥有GetMappings,但您正在发帖。
  • 哦!你的项目应该是buttons 或inputs。
  • 为什么你不能做简单的 导出到.CSV

标签: java html spring-boot


【解决方案1】:

以上解决方案

<a href = /coaExport?action=csv> Export to .CSV 

有效。感谢您的帮助

【讨论】:

    猜你喜欢
    • 2018-03-10
    • 2013-01-03
    • 2019-02-24
    • 2015-02-01
    • 1970-01-01
    • 2020-01-14
    • 2016-09-17
    • 2019-10-13
    • 2020-08-23
    相关资源
    最近更新 更多