日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【若依(ruoyi)】字典管理

發布時間:2024/9/19 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【若依(ruoyi)】字典管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  • 若依(ruoyi): v4.3

字典配置

系統管理 > 字典管理

DictService

DictService 類位于 com.office.framework.web.service 包中。該類作為 spring 的 Bean (bean name : dict),在 Thymeleaf 中使用。

DictUtils

DictUtils 類位于 com.office.framework.web.service 包中。該類作為 spring 的 Bean (bean name : dictUtils),在導出 Excel 功能中(被 ExcelUtil 類)使用。

在 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 項目中的 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">工作狀態:</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">回顯數據字典值:</label> <div class="form-control-static" th:text="${@dict.getLabel('sys_normal_disable', status)}"> </div>

在 Thymeleaf 模板的 table 中使用

// 獲取數據字典數據 var disableDictDatas = [[${@dict.getType('sys_normal_disable')}]];// 初始化表格 var options = {url: prefix + "/list",...{field: 'disable',title: '是否禁用',// 格式化數據字典formatter: function(value, row, index) {return $.table.selectDictLabel(disableDictDatas, value);}},...] }; $.table.init(options);

在 @Excel 注解中使用

/** 資產來源 */ @Excel(name = "資產來源", dictType = "ass_assets_source") private String source;

注:當實體類的屬性關聯字典時,類型必須為String類型。否則,將不能將字典 value 轉換成字典 label 。

因為將字典 value 轉換成字典 label 是使用 DictUtils 類的 getDictLabel 方法。public static String getDictLabel(String dictType, String dictValue) 方法的定義只能接受 String 類型的字典 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

總結

以上是生活随笔為你收集整理的【若依(ruoyi)】字典管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。