在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ thymeleaf url 拼接

thymeleaf url 拼接

一、問題描述
這是我的controller。傳遞了一個list給前臺頁面

@GetMapping(path = "/",produces = "text/json;charset=UTF-8")
    public ModelAndView index() {
        ModelAndView model =new ModelAndView();
        try{
            List<String> list = productService.getAllYear();
            model.addObject("years",list);
            model.setViewName("index");
        }catch (Exception e) {
            e.printStackTrace();
            model.addObject("error",ERROR_INFO);
            model.setViewName("error");
        }
        return model;
    }

這是我的前臺頁面的主要代碼

<a  href="months" th:each="year : ${years}" th:text="${year}+'年'"class="list-group-item"></a>

二、需求描述
我想在 href 中,根據 ${year}的值動態(tài)生成url 。 例如生成 months/2017。 請問怎么做?就使用thymeleaf 的語法可以做嗎? 或者有其他做法?

回答
編輯回答
獨特范
<a th:href="'/month/' + ${year}" th:each="year : ${years}" th:text="${year}+'年'"class="list-group-item"></a>

示例:
clipboard.png

2018年4月3日 12:04