前台页面标签:
<select name="roomTag" class="form-control m-b" th:with="type=${@dict.getType('lndoor_sensor_position')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
th:selected="${#strings.contains(dict.dictValue,mLndoorSensor.roomTag)? true:false}" ></option>
</select>
后台Service:
/**
* RuoYi首创 html调用 thymeleaf 实现字典读取
*
* @author ruoyi
*/
@Service("dict")
public class DictService
{
@Autowired
private DictDataService dictDataService;
/**
* 根据字典类型查询字典数据信息
*
* @param dictType 字典类型
* @return 参数键值
*/
public List<DictData> getType(String dictType) {
List<DictData> list=dictDataService.selectDictDataByType(dictType);
return list;
}
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
public String getLabel(String dictType, String dictValue) {
return dictDataService.selectDictLabel(dictType, dictValue);
}
}