thymeleaf 直接調用后台Service


前端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);
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM