0

如果按下按钮,我希望执行 showEnteredData 方法。但它不执行该功能。我认为它应该自动完成。问题是什么?感谢您的帮助:=)

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>

    <div id="leer" style="float: left;"></div>
    <div class="filmFilter">
        <form action="articles" method="get">

            <select name="dropdownFilmeFilter">
                <option value="aufsteigend">Preis: aufsteigend</option>
                <option value="absteigend">Preis: absteigend</option>
                <option value="bewertung">Kundenbewertung</option>
                <option value="erscheinungsdatum">Erscheinungsdatum</option>
            </select>

            <input type="submit" value="Done" /> <a href="home">bring me back
                home</a>
        </form>

    </div>

@RequestMapping(value = "/articles")
public String showHome ( Model model){
    List<Article> article = (List<Article>) gd.findAll(Article.class);  
    model.addAttribute("articles", article);


    return "articles";
}


@RequestMapping(value = "/articles", method = RequestMethod.POST)
public String showEnteredData(@RequestParam("dropdownFilmeFilter") String filter, Model model) {
    System.err.println("hohooh");


    List<Article> article = (List<Article>) gd.sortByAttribute(Article.class, "price", true);
    article.clear();

    if (filter == "aufsteigend"){
        article = (List<Article>) gd.sortByAttribute(Article.class, "price", true);
    }
    model.addAttribute("articles", article);

    return "articles";
}
4

1 回答 1

3

您可以将表单标签中的方法更改为“post”,或者将@RequestMapping 的方法更改为RequestMethod.GET。我会推荐第一个选项。

于 2012-12-24T23:32:44.340 回答