目录
1、查询字典数据
前端 api:
// 根据字典类型查询字典数据信息
export function getDicts(dictType) {
return request({
url: '/system/dict/data/dictType/' + dictType,
method: 'get'
})
}
Controller 层:
package com.ruoyi.project.system.controller;
/**
* 数据字典信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {
@Resource
private ISysDictDataService dictDataService;
/**
* 根据字典类型查询字典数据信息
*/
@GetMapping(value = "/dictType/{dictType}")
public AjaxResult dictType(@PathVariable String dictType)
{
return AjaxResult.success(dictDataService.selectDictDataByType(dictType));
}
}
Service 接口层:
package com.ruoyi.project.system.service;
import com.ruoyi.project.system.domain.SysDictData;
import java.util.List;
/**
* 字典 业务层
*
* @author ruoyi
*/
public interface ISysDictDataService {
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
public List<SysDictData> selectDictDataByType(String dictType);
}
Service 实现类层
package com.ruoyi.project.system.service.impl;
/**
* 字典 业务层处理
*
* @author ruoyi
*/
@Service
public class SysDictDataServiceImpl implements ISysDictDataService {
@Resource
private SysDictDataMapper dictDataMapper;
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
@Override
public List<SysDictData> selectDictDataByType(String dictType) {
return dictDataMapper.selectDictDataByType(dictType);
}
}
Mapper 接口层:
package com.ruoyi.project.system.mapper;
/**
* 字典表 数据层
*
* @author ruoyi
*/
public interface SysDictDataMapper {
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
public List<SysDictData> selectDictDataByType(String dictType);
}
Mapper 映射文件:
创建 resources / mybatis / system / SysDictDataMapper.xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.system.mapper.SysDictDataMapper">
<resultMap type="SysDictData" id="SysDictDataResult">
<id property="dictCode" column="dict_code" />
<result property="dictSort" column="dict_sort" />
<result property="dictLabel" column="dict_label" />
<result property="dictValue" column="dict_value" />
<result property="dictType" column="dict_type" />
<result property="cssClass" column="css_class" />
<result property="listClass" column="list_class" />
<result property="isDefault" column="is_default" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<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>
</mapper>
2、查询参数配置(如初始化密码)
前端 API :
// 根据参数键名查询参数值
export function getConfigKey(configKey) {
return request({
url: '/system/config/configKey/' + configKey,
method: 'get'
})
}
Controller 层:
package com.ruoyi.project.system.controller;
/**
* 参数配置 信息操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/config")
public class SysConfigController extends BaseController {
@Resource
private ISysConfigService configService;
/**
* 根据参数键名查询参数值
*/
@GetMapping(value = "/configKey/{configKey}")
public AjaxResult getConfigKey(@PathVariable String configKey) {
return AjaxResult.success(configService.selectConfigByKey(configKey));
}
}
Service 接口层:
package com.ruoyi.project.system.service;
/**
* 参数配置 服务层
*
* @author ruoyi
*/
public interface ISysConfigService {
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数键名
* @return 参数键值
*/
public String selectConfigByKey(String configKey);
}
Service 接口实现类层:
package com.ruoyi.project.system.service.impl;
/**
* 参数配置 服务层实现
*
* @author ruoyi
*/
@Service
public class SysConfigServiceImpl implements ISysConfigService {
@Resource
private SysConfigMapper configMapper;
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数key
* @return 参数键值
*/
@Override
public String selectConfigByKey(String configKey) {
SysConfig config = new SysConfig();
config.setConfigKey(configKey);
SysConfig retConfig = configMapper.selectConfig(config);
return StringUtils.isNotNull(retConfig) ? retConfig.getConfigValue() : "";
}
}
SysConfig 实体类:
package com.ruoyi.project.system.domain;
/**
* 参数配置表 sys_config
*
* @author ruoyi
*/
public class SysConfig extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 参数主键 */
private Long configId;
/** 参数名称 */
private String configName;
/** 参数键名 */
private String configKey;
/** 参数键值 */
private String configValue;
/** 系统内置(Y是 N否) */
private String configType;
public Long getConfigId()
{
return configId;
}
public void setConfigId(Long configId)
{
this.configId = configId;
}
public String getConfigName()
{
return config