**
若依集成版框架的字典使用 如有看不懂的朋友可留言,博主会一一解答
**
单个值的回显
利用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);
}
}