前端thymeleaf
<select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
拼接后台獲取的數據 '__${ }__', 前后都是兩個下划線 ,加單引號往后台傳的時候是字符串,不加單引號往后台傳的是數字, __${ }__
<input class="form-control m-b" th:with="type=${@dict.getLabel('sys_user_sex','__${hrmResource.sex}__')}" th:value="${type}" >
<div class="m-b" th:with="type=${@dict.getLabel('sys_blood','__${hrmResource.bloodType}__')}">[[${type}]]</div>
后台 Spring boot
/**
* html調用 thymeleaf 實現字典讀取
*/
@Service("dict")
public class DictService
{
@Autowired
private IDictDataService dictDataService;
/**
* 根據字典類型查詢字典數據信息
*
* @param dictType 字典類型
* @return 參數鍵值
*/
public List<DictData> getType(String dictType)
{
return dictDataService.selectDictDataByType(dictType);
}
/**
* 根據字典類型和字典鍵值查詢字典數據信息
*
* @param dictType 字典類型
* @param dictValue 字典鍵值
* @return 字典標簽
*/
public String getLabel(String dictType, String dictValue)
{
return dictDataService.selectDictLabel(dictType, dictValue);
}
}