注:代码来自于若依框架RuoYi-master

实现效果在这里插入图片描述

字典表

在这里插入图片描述

核心代码

视图层:

<select name="sex" th:with="type=${@dict.getType('sys_customer_sex')}">
   <option value="">所有</option>
   <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option                                  
</select>

service层

@Service("dict")
public class DictService
{
    @Autowired
    private ISysDictTypeService dictTypeService;
    public List<SysDictData> getType(String dictType)
    {
        return dictTypeService.selectDictDataByType(dictType);
    }    
    
} 

mapper.xml层

<sql id="selectDictDataVo">
        select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark 
		from sys_dict_data
</sql>
<select id="selectDictDataByType" parameterType="SysDictData" resultMap="SysDictDataResult">
		<include refid="selectDictDataVo"/>
		where status = '0' and dict_type = #{dictType} order by dict_sort asc
	</select>
Logo

快速构建 Web 应用程序

更多推荐