日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【若依(ruoyi)】字典管理

發(fā)布時(shí)間:2024/9/19 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【若依(ruoyi)】字典管理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

  • 若依(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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。