【若依(ruoyi)】字典管理
前言
- 若依(ruoyi): v4.3
字典配置
系統(tǒng)管理 > 字典管理
DictService
DictService 類(lèi)位于 com.office.framework.web.service 包中。該類(lèi)作為 spring 的 Bean (bean name : dict),在 Thymeleaf 中使用。
DictUtils
DictUtils 類(lèi)位于 com.office.framework.web.service 包中。該類(lèi)作為 spring 的 Bean (bean name : dictUtils),在導(dǎo)出 Excel 功能中(被 ExcelUtil 類(lèi))使用。
在 Thymeleaf 模板的 Select 中使用
<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}"><option value="">所有</option><option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option> </select>注:在 spring boot 項(xiàng)目中的 Thymeleaf 模板中,Access any beans in your application context using SpringEL’s syntax: ${@myBean.doSomething()}。
在 Thymeleaf 模板的 Radio 中使用
<div class="form-group"> <label class="col-sm-3 control-label">工作狀態(tài):</label><div class="col-sm-8"><div class="radio-box" th:each="dict : ${@dict.getType('sys_staff_state')}"><input type="radio" th:id="${dict.dictCode}" th:value="${dict.dictValue}"><label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label></div></div> </div>在 Thymeleaf 模板中作為回顯使用
<label class="col-sm-2 control-label">回顯數(shù)據(jù)字典值:</label> <div class="form-control-static" th:text="${@dict.getLabel('sys_normal_disable', status)}"> </div>在 Thymeleaf 模板的 table 中使用
// 獲取數(shù)據(jù)字典數(shù)據(jù) var disableDictDatas = [[${@dict.getType('sys_normal_disable')}]];// 初始化表格 var options = {url: prefix + "/list",...{field: 'disable',title: '是否禁用',// 格式化數(shù)據(jù)字典formatter: function(value, row, index) {return $.table.selectDictLabel(disableDictDatas, value);}},...] }; $.table.init(options);在 @Excel 注解中使用
/** 資產(chǎn)來(lái)源 */ @Excel(name = "資產(chǎn)來(lái)源", dictType = "ass_assets_source") private String source;注:當(dāng)實(shí)體類(lèi)的屬性關(guān)聯(lián)字典時(shí),類(lèi)型必須為String類(lèi)型。否則,將不能將字典 value 轉(zhuǎn)換成字典 label 。
因?yàn)閷⒆值?value 轉(zhuǎn)換成字典 label 是使用 DictUtils 類(lèi)的 getDictLabel 方法。public static String getDictLabel(String dictType, String dictValue) 方法的定義只能接受 String 類(lèi)型的字典 value 。
如果重載(overload)該方法,也可以。比如:public static String getDictLabel(String dictType, int dictValue) 。
參考
https://doc.ruoyi.vip/ruoyi/document/qdsc.html#字典使用
https://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#the-springstandard-dialect
https://blog.csdn.net/weixin_42517667/article/details/82526675
總結(jié)
以上是生活随笔為你收集整理的【若依(ruoyi)】字典管理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 咖啡因有什么作用
- 下一篇: 【spring boot】Control