Spring Boot中yml配置文件Map集合注入及使用方式

 

 

yml配置文件

maps: "{key1: 'value1', key2: 'value2'}"

 

java中

@Value("#{${maps}}")  
private LinkedHashMap maps;

 我这里之所以用LinkedHashMap类型 是因为我想要是有序的 可以根据自己的来




thymeleaf遍历
<select class="form-control" name="maps" >
    <option th:each="item,m:${map}" th:value="${m.current.key}"  th:text="${m.current.value}" required></option>
</select>

 

 

 

 






posted @ 2021-05-09 15:30  yvioo  阅读(4918)  评论(0编辑  收藏  举报