In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use SpringBoot+MyBatisPlus+MySQL8 to achieve tree structure query". In daily operation, I believe many people have doubts about how to use SpringBoot+MyBatisPlus+MySQL8 to achieve tree structure query. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use SpringBoot+MyBatisPlus+MySQL8 to achieve tree structure query". Next, please follow the editor to study!
Scene:
When implementing the permission function module, it is necessary to return the queried permission data to the front end in the way of tree structure.
Function realization:
Step 1: the structure definition of permission table and its function demonstration data.
DROP TABLE IF EXISTS `baoan_ privilege` CREATE TABLE `baoan_ privilege` (`id` varchar (64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'primary key', `privilege_ name` varchar 'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT' permission name', `privilege_ code` varchar (100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'permission coding', `pid`varchar (64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'parent Id' `url`varchar (200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'menu routing', `url`int (3) NULL DEFAULT NULL COMMENT 'serial number', `privilege_ type` varchar (32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'permission type 1: project 2 menu 3 buttons', `state`varchar (10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT'2' COMMENT 'status (1: disable, 2: enable)', `created_ by`varchar (32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'creator', `created_ dt`datetime (0) NULL DEFAULT NULL COMMENT 'creation time', `version`int (9) NULL DEFAULT 1 COMMENT 'version number', `state`varchar (10) varchar 'permission description', `state`datetime (10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT'2' COMMENT 'status (1: disable, 2: enable)', `stateby` varchar (32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'creator', `version`int (9) NULL DEFAULT 1 COMMENT 'version' `icon_ by` varchar (32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'update person', `updated_ dt` datetime (0) NULL DEFAULT NULL COMMENT 'update time', `delete_ name` int (15) NULL DEFAULT NULL COMMENT 'icon name', `delete_ identity (1) NULL DEFAULT 1 COMMENT 'deletion ID (1: not deleted 2: deleted)', PRIMARY KEY (`id`) USING BTREE) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'permission table' ROW_FORMAT = Dynamic -Records of baoan_privilege-- INSERT INTO `baoan_ privilege VALUES ('1blank,' homepage', 'Aids,' 0questions, NULL, NULL, '1stories,' home pages', '2posts, NULL, NULL, 1, NULL, 1) INSERT INTO `notification, NULL, NULL, INSERT INTO `notification, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege VALUES ('11log,' operation log', 'Fido 03log,' 6levels, NULL, NULL, '2operations,' operation log', '2records, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 12 roles, 'role Management', 'Fido 04,' 6 roles, NULL, NULL,'2 roles, 'role Management,' 2 roles, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 13customers, 'storage management', 'Fair05stores,' 6clients, NULL, NULL, '2clients,' storage management', '2clients, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 14levels, 'rights management', 'Fido 06managers,' 6cycles, NULL, NULL, '2permissions,' rights management', '2records, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 15 years, 'new', 'Fido 01 added,' 9 percent, NULL, NULL,'3 percent, 'administrator add','2 percent, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 16 years, 'modify', 'Fido 01 updated updated,' 9 percent, NULL, NULL,'3 percent, 'administrator modification','2 changes, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 17 queries, 'query', 'Fido 01 searching,' 9 queries, NULL, NULL,'3 queries, 'Administrator query,' 2 queries, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 18, 'delete,' Full01 deleted,'9 deleted, NULL, NULL,'3 deleted, 'administrator deleted','2 deleted, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege` VALUES ('1900,' export', 'Found01exports,' 9exports, NULL, NULL, '3exports,' administrator exports', '2exports, NULL, NULL, 1, NULL, 1) INSERT INTO `NULL privilege` VALUES ('2customers,' user management', 'blog,' 0customers, NULL, NULL, '1customers,' user management', '2customers, NULL, NULL, 1, NULL, 1); INSERT INTO `baoan_ privileges' VALUES ('3customers,' mall management', 'accounts,' NULL, NULL, '1customers,' mall management', '2customers, NULL, NULL, 1, NULL, 1) INSERT INTO `NULL, NULL, '1commodity,' INSERT INTO', NULL, NULL, 1, NULL, 1); INSERT INTO `baoan_ privilege 'VALUES (' 5percent, 'promotion management', 'promotion,' NULL, NULL, '1promotion,' promotion management, '2customers, NULL, NULL, 1, NULL, 1) INSERT INTO `baoan_ privilege 'VALUES (' 6percent, 'system Administration', 'Fables,' 0requests, NULL, NULL, '1requests,' system Administration', '2programs, NULL, NULL, 1, NULL, 1); INSERT INTO `baoan_ privilege' VALUES ('7requests,' configuration Management', 'Gateway,' NULL, NULL, '1configuration,' configuration Management, '2cycles, NULL, NULL, 1, NULL, 1) INSERT INTO `NULL, NULL, '1statistics,' INSERT INTO', NULL, NULL, 1, NULL, 1); INSERT INTO `baoan_ privilege 'VALUES (' 9 minutes, 'administrator', 'Fairchild 01,' 6 percent, NULL, NULL,'2 minutes, 'administrator','2 minutes, NULL, NULL, 1, NULL, 1)
Step 2: definition of permissions table entity and its extension object
Basic object
Package com.zzg.entity; import java.io.Serializable;import java.util.Date; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @ SuppressWarnings ("serial") @ TableName (value = "baoan_privilege") @ Datapublic class BaoanPrivilege implements Serializable {private String id; private String privilegeName; private String privilegeCode; private String pid; private String url; private Integer orderRank; private String privilegeType; private String privilegeDescription; private String state; private String createdBy; private Date createdDt Private Integer version; private String updatedBy; private Date updatedDt; private Integer iconName; private Integer deleteFlag;}
Expand the object
Package com.zzg.vo; import java.util.List; import com.zzg.entity.BaoanPrivilege; import lombok.Data; @ SuppressWarnings ("serial") @ Datapublic class BaoanPrivilegeVo extends BaoanPrivilege {private List children;}
Step 3: permission table Mapper definition
Mapper interface definition
Package com.zzg.mapper; import java.util.List;import java.util.Map; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import com.zzg.entity.BaoanPrivilege;import com.zzg.vo.BaoanPrivilegeVo; public interface BaoanPrivilegeMapper extends BaseMapper {List selectList (Map parameter); IPage selectPage (Page page, @ Param ("vo") Map parameter);}
Mapper.xml file definition
Id, privilege_name, privilege_code, pid, url, order_rank, privilege_type, privilege_description, state, created_by, created_dt, version, updated_by, updated_dt, icon_name Delete_flag and baoan_privilege.privilege_type = # {privilegeType} and baoan_privilege.pid = # {pid} and baoan_privilege.privilege_type = # {vo.privilegeType} and baoan_privilege.pid = # {vo.pid} SELECT FROM baoan_privilege WHERE pid = # {id} select FROM baoan_privilege WHERE 1 = 1 select FROM baoan_privilege WHERE 1 = 1
Step 3: permission table Service definition
Package com.zzg.service; import java.util.List;import java.util.Map; import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import com.baomidou.mybatisplus.extension.service.IService;import com.zzg.entity.BaoanPrivilege;import com.zzg.vo.BaoanPrivilegeVo; public interface BaoanPrivilegeService extends IService {List selectList (Map parameter); IPage selectPage (Page page, Map parameter);} package com.zzg.service.impl; import java.util.List;import java.util.Map Import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import com.zzg.entity.BaoanPrivilege;import com.zzg.mapper.BaoanPrivilegeMapper;import com.zzg.service.BaoanPrivilegeService;import com.zzg.vo.BaoanPrivilegeVo; @ Servicepublic class BaoanPrivilegeServiceImpl extends ServiceImpl implements BaoanPrivilegeService {@ Autowired private BaoanPrivilegeMapper mapper Override public List selectList (Map parameter) {/ / TODO Auto-generated method stub return mapper.selectList (parameter);} @ Override public IPage selectPage (Page page, Map parameter) {/ / TODO Auto-generated method stub return mapper.selectPage (page, parameter);}}
Step 4: the controller layer interface provides services.
/ check @ ApiOperation (httpMethod = "POST", value = "query eligible permission records based on paging") @ RequestMapping (value = "/ getPage", method = {RequestMethod.POST}) @ ApiImplicitParams ({@ ApiImplicitParam (name = "username", value = "administrator name", required = false, dataType = "String", paramType = "query")} public Result getPage (@ RequestBody Map parame) {/ / dynamic build add parameter / / QueryWrapper query = new QueryWrapper () / / this.buildQuery (parame, query); PageParame pageParame = this.initPageBounds (parame); Page page = new Page (pageParame.getPage (), pageParame.getLimit ()); IPage list = baoanPrivilegeService.selectPage (page, parame); return Result.ok (). SetDatas (list);}
Front-end effect display:
At this point, the study on "how to use SpringBoot+MyBatisPlus+MySQL8 to implement tree structure query" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.