template里面的vue代码
获取数据(手动查询字典数据)
// 获取字典数据和业务表的数据比对,如果是同一个key,会显示对应字典的value
添加下拉框的标签; dictOptionsShowAppType是数据
定义数据: dictOptionsShowAppType: undefined,
引入jd
获取数据
解决方案: modelCategory是列表显示字段;sexFormat定义点击事件
先查询字典树的所有列表数据,注意是列表,不是树结构
control代码
/ * 获取字典树列表 */ @GetMapping("/dictTree") public AjaxResult deptTree(LowModelDict dept) { return success(lowModelDictService.selectLowModelDictTreeList(dept)); }
service实现类
@Override public List<TreeSelect> selectLowModelDictTreeList(LowModelDict dept) { // 如果不传父级结构,指定一个父级结构 if( StringUtils.isBlank( dept.getDictCode() )){ dept.setDictCode("increment_type"); } // 查询单条父级数据 LowModelDict lowModelDict = lowModelDictMapper.selectOneModelDict(dept); // 查询全部数据 List<LowModelDict> depts = lowModelDictMapper.selectLowModelDictList(dept); List<TreeSelect> treeSelects = buildDeptTreeSelect(depts, lowModelDict ); return treeSelects; } public List<TreeSelect> buildDeptTreeSelect(List<LowModelDict> depts, LowModelDict lowModelDict ) { List<LowModelDict> deptTrees = buildDeptTree(depts , lowModelDict ); return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); } public List<LowModelDict> buildDeptTree(List<LowModelDict> depts, LowModelDict lowModelDict) { List<LowModelDict> returnList = new ArrayList<LowModelDict>(); // List<Long> tempList = depts.stream().map(LowModelDict::getId).collect(Collectors.toList()); // 获取所有的树结构数据 Long id = lowModelDict.getId(); for (LowModelDict dept : depts) { // 如果是顶级节点, 遍历该父节点的所有子节点 // if (!tempList.contains(dept.getParentId())) { // 获取所有的树结构数据 // if ( id.longValue() == dept.getParentId().longValue() ) { // 不包括父级 if ( id.longValue() == dept.getId().longValue() ) { // 包括父级 recursionFn(depts, dept); returnList.add(dept); } } if (returnList.isEmpty()) { returnList = depts; } return returnList; } / * 递归列表 */ private void recursionFn(List<LowModelDict> list, LowModelDict t) { // 得到子节点列表 List<LowModelDict> childList = getChildList(list, t); t.setChildren(childList); for (LowModelDict tChild : childList) { if (hasChild(list, tChild)) { recursionFn(list, tChild); } } } private boolean hasChild(List<LowModelDict> list, LowModelDict t) { return getChildList(list, t).size() > 0; } / * 得到子节点列表 */ private List<LowModelDict> getChildList(List<LowModelDict> list, LowModelDict t) { List<LowModelDict> tlist = new ArrayList<LowModelDict>(); Iterator<LowModelDict> it = list.iterator(); while (it.hasNext()) { LowModelDict n = (LowModelDict) it.next(); if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) { tlist.add(n); } } return tlist; }
mapper接口
/ * 查询数据字典列表 * * @param lowModelDict 数据字典 * @return 数据字典集合 */ public List<LowModelDict> selectLowModelDictList(LowModelDict lowModelDict);
// 查询单条父级数据 LowModelDict selectOneModelDict(LowModelDict lowModelDict);
xml的sql
// 查询单条父级数据 <select id="selectOneModelDict" parameterType="LowModelDict" resultMap="LowModelDictResult"> SELECT * FROM low_model_dict where dict_code = #{dictCode} </select>
查询数据字典列表
<sql id="selectLowModelDictVo"> select id, parent_id, dict_code, dict_label, dict_sort, dict_flag, dict_1, dict_2, dict_3, dict_4, dict_5, dict_seq, status, create_by, create_date, update_by, update_date, remarks from low_model_dict </sql> <select id="selectLowModelDictList" parameterType="LowModelDict" resultMap="LowModelDictResult"> <include refid="selectLowModelDictVo"/> <where> <if test="dictLabel != null and dictLabel != ''"> and dict_label like concat('%', #{dictLabel}, '%')</if> <if test="remarks != null and remarks != ''"> and remarks = #{remarks}</if> </where> </select>
实体类;注意这里是继承 BaseEntity
// 处理Long 类型 返回前端精度丢失问题 @Bean public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { ObjectMapper objectMapper = builder.createXmlMapper(false).build(); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); return objectMapper; }
commin 模块 pom.xml
<!-- 新增依赖 --> <!-- mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> </dependency>
最外层的pom.xml
<!-- 新增依赖 --> <!-- mybatis plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatis-plus.version}</version> </dependency> <!-- pagehelper 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>${pagehelper.boot.version}</version> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> </dependency>
注释原来 MyBatisConfig
添加 MybatisPlus 的配置类 MybatisPlusConfig
修改 BaseEntity 类 ;移除部分不用的字段;不移除 mp 查询会报错;因为数据库没相关字段 @TableField(exist = false)
修改配置 application.yml 文件;移除mybatis的配置,添加mybatisPlus的配置
集成 mybatisplus 的分页查询 IPage
基础实体类继承分页参数类;BaseEntity extends PageDomain
注意、注意、注意
PageDomain 分页类要移除相关字段,数据库表没有相关字段,否则mp查询报错
添加依赖 ruoyi-framework
<!-- 新增依赖 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version> </dependency>
添加自动填充配置类 MyMetaObjectHandler;注意 createTime、createDate等字段在实体类要配置注解;
基础实体类 BaseEntity 字段要添加注解;
@TableField(value = "create_time",fill = FieldFill.INSERT) // 要和数据库一致
如果业务实体类 LowModelCode 里面有需要自动填充的字段;也要添加注解
@TableField(value = "create_time",fill = FieldFill.INSERT) // 要和数据库一致
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/bcyy/13685.html