若依的字典使用

本文详细介绍了如何在若依集成版框架中使用Thymeleaf进行字典数据的回显,包括单个值的显示和循环下拉列表的实现。通过示例代码展示了如何编写业务逻辑层类,以及`dict.getLabel`和`dict.getType`方法的使用,帮助读者理解并应用到实际项目中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

**

若依集成版框架的字典使用 如有看不懂的朋友可留言,博主会一一解答

**

单个值的回显
利用thymeleaf框架th:text 方法 双引号中写@dict.getLabel(’ ')传入所要的参数即可取出对应的值。


<label class="col-sm-2 control-label">回显数据字典单个的值:</label>
	<div class="form-control-static" th:text="${@dict.getLabel('sys_normal_disable', status)}">
</div>

循环下拉列表回显多个值
利用@dict.getType方法查询要循环的字典类型,然后用type接受,用th:each去循环获取所要的值。


<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>
  • 编写一个业务逻辑层类
  • 利用@Service设置service名字
  • 注入进需要调用的service接口

*  @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private ISysDictDataService dictDataService;

编写需要请求的方法

* 
*  /**
     * 根据字典类型查询字典数据信息
     * 
     * @param dictType 字典类型
     * @return 参数键值
     */
    public List<SysDictData> getType(String dictType)
    {
        return dictTypeService.selectDictDataByType(dictType);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    public String getLabel(String dictType, String dictValue)
    {
        return dictDataService.selectDictLabel(dictType, dictValue);
    }

以下是所有具体的方法:
利用@Service注解 写入自己所要的名称
然后再前台可利用
th:text="${@dict.getLabel(‘sys_normal_disable’, status)}"
的方式传入所要的参数,具体取决于你自己所写的方法决定

@Service("dict")
public class DictService
{
    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private ISysDictDataService dictDataService;

    /**
     * 根据字典类型查询字典数据信息
     * 
     * @param dictType 字典类型
     * @return 参数键值
     */
    public List<SysDictData> getType(String dictType)
    {
        return dictTypeService.selectDictDataByType(dictType);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    public String getLabel(String dictType, String dictValue)
    {
        return dictDataService.selectDictLabel(dictType, dictValue);
    }
}
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值