엄지월드

thymeleaf hashmap get key, value 본문

java/Spring

thymeleaf hashmap get key, value

킨글 2022. 8. 30. 08:29

Controller

@GetMapping(value= {"/admin/banner/add.do", "/admin/banner/edit.do"})
public String add(Model model ) {
    HashMap<String, String> targetList = new HashMap<>();
    targetList.put(TARGET_BLANK, "새 창");
    targetList.put(TARGET_EMPTY, "현재 창");
    
    model.addAttribute("bannerCodeList", targetList);
}

Html

<option th:each="x : ${bannerCodeList}"
        th:value="${x['key']}"
        th:text="${x['value']}"
>value가 없으면 노출될 텍스트</option>


<!--                        <option th:each="x : ${bannerCodeList}"-->
<!--                                th:selected="${banner.target == x['key']}"-->
<!--                        >창</option>-->

 

Comments