当前位置: 首页 > news >正文

湖北省建设厅官方网站电话网站软文代写

湖北省建设厅官方网站电话,网站软文代写,做网站从哪里做,建筑模板是干嘛用的数据库关系有父子id的, 作为菜单栏展示时需要用前端需要用到懒加载, 所谓懒加载就是接口有一个标志位isLeaf, 前端请求后通过该字段判断该节点是否还有子节点数据 创建数据库表 t_company_info结构有id和parentId标识, 用来表示父子关系 /*Navicat Premium Data TransferSourc…

数据库关系有父子id的, 作为菜单栏展示时需要用前端需要用到懒加载, 所谓懒加载就是接口有一个标志位isLeaf, 前端请求后通过该字段判断该节点是否还有子节点数据

创建数据库表 t_company_info结构有id和parentId标识, 用来表示父子关系

/*Navicat Premium Data TransferSource Server         : mysql8.0Source Server Type    : MySQLSource Server Version : 80029 (8.0.29)Source Host           : localhost:3307Source Schema         : springboot_mybatisTarget Server Type    : MySQLTarget Server Version : 80029 (8.0.29)File Encoding         : 65001*/SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
-- Table structure for t_company_info
-- ----------------------------
DROP TABLE IF EXISTS `t_company_info`;
CREATE TABLE `t_company_info`  (`id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id',`company_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '公司名',`parent_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '父节点id',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;-- ----------------------------
-- Records of t_company_info
-- ----------------------------
INSERT INTO `t_company_info` VALUES ('1', '旺旺集团', '0');
INSERT INTO `t_company_info` VALUES ('2', '广州分部', '1');
INSERT INTO `t_company_info` VALUES ('3', '深圳分部', '1');
INSERT INTO `t_company_info` VALUES ('4', '福田区分公司', '3');
INSERT INTO `t_company_info` VALUES ('5', '南山区分公司', '3');SET FOREIGN_KEY_CHECKS = 1;

有需要的配置文件 application.yml 可参考

spring:datasource:username: #填写账号password: #填写密码url: jdbc:mysql://localhost:3307/springboot_mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true#&allowPublicKeyRetrieval=true这一部分设置是mysql8里面的, 不设置验证会报错driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourcedruid:stat-view-servlet:enabled: truelogin-username: login-password: web-stat-filter:enabled: true#  sql:
#    init:
#      schema-locations: classpath:sql/schema.sql
#      mode: always
server:port: 8089logging:level:root: info  #日志等级com.example.mybatis_plus: info
mybatis-plus:configuration:map-underscore-to-camel-case: true  #下划线转驼峰global-config:db-config:logic-not-delete-value: 0  #逻辑删除logic-delete-field: 1
#  type-enums-package: com.example.mybatis_plus.enums.statusEnum
1.创建实体类
package com.example.mybatis_plus.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;import java.io.Serializable;/*** <p>* * </p>** @author * @since 2023-04-01*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_company_info")
@ApiModel(value="CompanyInfo对象", description="")
public class CompanyInfo implements Serializable {private static final long serialVersionUID = 1L;@ApiModelProperty(value = "id")@TableId(value = "id", type = IdType.ASSIGN_UUID)private String id;@ApiModelProperty(value = "公司名")private String companyName;@ApiModelProperty(value = "父节点id")private String parentId;}
2.创建service接口
package com.example.mybatis_plus.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.example.mybatis_plus.entity.CompanyInfo;import java.util.List;/*** <p>*  服务类* </p>** @author * @since 2023-04-01*/
public interface CompanyInfoService extends IService<CompanyInfo> {/*** 获得指定父节点的子节点列表* @param parentId 父节点ID* @return 子节点列表*/List<CompanyInfo> getChildNodes(String parentId);
}
3.完成其实现类
package com.example.mybatis_plus.service.impl;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mybatis_plus.entity.CompanyInfo;
import com.example.mybatis_plus.mapper.CompanyInfoMapper;
import com.example.mybatis_plus.service.CompanyInfoService;
import org.springframework.stereotype.Service;import java.util.List;/*** <p>*  服务实现类* </p>** @author * @since 2023-04-01*/
@Service
public class CompanyInfoServiceImpl extends ServiceImpl<CompanyInfoMapper, CompanyInfo> implements CompanyInfoService {@Overridepublic List<CompanyInfo> getChildNodes(String parentId) {List<CompanyInfo> list=list(new QueryWrapper<CompanyInfo>().eq("parent_id",parentId));return list;}
}
4.mapper接口
package com.example.mybatis_plus.mapper;import com.example.mybatis_plus.entity.CompanyInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;/*** <p>*  Mapper 接口* </p>** @author * @since 2023-04-01*/
public interface CompanyInfoMapper extends BaseMapper<CompanyInfo> {}
5.mapper文件
<?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.example.mybatis_plus.mapper.CompanyInfoMapper"><!-- 通用查询映射结果 --><resultMap id="BaseResultMap" type="com.example.mybatis_plus.entity.CompanyInfo"><id column="id" property="id" /><result column="company_name" property="companyName" /><result column="parent_id" property="parentId" /></resultMap><!-- 通用查询结果列 --><sql id="Base_Column_List">id, company_name, parent_id</sql></mapper>
6.result统一结果封装类
@Data
public class Result implements Serializable {private int code;private String msg;private Object data;public static Result success(Object data) {return success(200, "操作成功", data);}public static Result success() {return success(200, "操作成功", null);}public static Result success(int code, String msg, Object data) {Result r = new Result();r.setCode(code);r.setMsg(msg);r.setData(data);return r;}public static Result fail(String msg) {return fail(400, msg, null);}public static Result fail(int code, String msg, Object data) {Result r = new Result();r.setCode(code);r.setMsg(msg);r.setData(data);return r;}}
6.创建树形结构实体类TreeNode
package com.example.mybatis_plus.entity;import lombok.Data;/*** @author * @description TODO* @date 2023-04-01*/
@Data
public class TreeNode {private String id;private String companyName;private String parentId;private Boolean isLeaf;public TreeNode(String id, String companyName, String parentId, Boolean isLeaf) {this.id = id;this.companyName = companyName;this.parentId = parentId;this.isLeaf = isLeaf;}
}
7.CompanyInfoController控制层
package com.example.mybatis_plus.controller;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatis_plus.common.Result;
import com.example.mybatis_plus.entity.CompanyInfo;
import com.example.mybatis_plus.entity.TreeNode;
import com.example.mybatis_plus.service.CompanyInfoService;
import com.example.mybatis_plus.utils.ParamUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;/*** <p>* * </p>** @author * @since 2023-04-01*/
@Api(value = "", tags = "")
@RestController
@RequestMapping("/companyInfo")
//@Slf4j
public class CompanyInfoController {@Autowiredprivate CompanyInfoService companyInfoService;@ApiOperation(value = "查询分页数据")@PostMapping(value = "/list")public Result list(@RequestBody(required = false) Map<String, Object> object) {Page<CompanyInfo> page = ParamUtils.toPage(CompanyInfo.class, object);CompanyInfo entity = ParamUtils.toEntity(CompanyInfo.class, object);QueryWrapper<CompanyInfo> qw = new QueryWrapper<>();if (null != entity) {qw.setEntity(entity);}// qw.orderByAsc("");page = companyInfoService.page(page, qw);return Result.success(page);}@ApiOperation(value = "根据id查询数据")@GetMapping(value = "/get")public Result get(String id) {if (null == id || id.equals("")) {return Result.fail("ID不能为空!");}CompanyInfo entity = companyInfoService.getById(id);return Result.success(entity);}/*** 输入 parentId** @param map* @return*/@ApiOperation(value = "获得指定父节点的子节点列表")@PostMapping(value = "/getChildNodes")public Result getChildNodes(@RequestBody Map<String, Object> map) {if (map.isEmpty()) {return Result.fail("输入格式错误");}String parentId = ParamUtils.toString(map, "parentId");
//        List<CompanyInfo> ngPowerTransformerInfoList = CompanyInfoService.getChildNodes(parentId);List<CompanyInfo> ngPowerTransformerInfoList = companyInfoService.getChildNodes(parentId);ArrayList<TreeNode> treeNodes = new ArrayList<>();for (CompanyInfo CompanyInfo : ngPowerTransformerInfoList) {String CompanyId = CompanyInfo.getId();String CompanyParentId = CompanyInfo.getParentId();String companyName = CompanyInfo.getCompanyName();boolean isLeaf = true;List<CompanyInfo> childNodes = companyInfoService.getChildNodes(CompanyId);if (childNodes.size() > 0) {isLeaf = false;}TreeNode treeNode = new TreeNode(CompanyId, companyName, CompanyParentId, isLeaf);treeNodes.add(treeNode);}return Result.success(treeNodes);}@ApiOperation(value = "新增/修改数据")@PostMapping(value = "/save")public Result save(HttpServletRequest request, @RequestBody CompanyInfo entity) {if (null == entity) {return Result.fail("对象不能为空!");}companyInfoService.saveOrUpdate(entity);return Result.success(entity);}@ApiOperation(value = "批量删除数据")@PostMapping(value = "/delete")public Result delete(HttpServletRequest request, @RequestBody List<String> idList) {if (null == idList || idList.isEmpty()) {return Result.fail("对象不能为空!");}companyInfoService.removeByIds(idList);return Result.success();}}

ps

String parentId = ParamUtils.toString(map, "parentId");
ParamUtils工具类有点多, 就不做展示了
就是将map里面的parentId取出来
8.结果演示
8.1请求父节点为0的数据, 只有集团总部, 并且还有子节点所以isLeaf为false

image-20230401222423508

8.2请求父id为1的数据,广州分部没有子节点, isLeaf为true,深圳有子节点,isLeaf为false

image-20230401222606121

8.3请求父id为3的数据, 同理

image-20230401222935783


文章转载自:
http://hose.bbmx.cn
http://toolbox.bbmx.cn
http://verification.bbmx.cn
http://pasta.bbmx.cn
http://instigator.bbmx.cn
http://monandrous.bbmx.cn
http://kamela.bbmx.cn
http://minded.bbmx.cn
http://thermopane.bbmx.cn
http://croma.bbmx.cn
http://aprism.bbmx.cn
http://masonry.bbmx.cn
http://pilfer.bbmx.cn
http://hist.bbmx.cn
http://issueless.bbmx.cn
http://catherine.bbmx.cn
http://concessively.bbmx.cn
http://avt.bbmx.cn
http://gonfalonier.bbmx.cn
http://acquiescence.bbmx.cn
http://cienaga.bbmx.cn
http://unwise.bbmx.cn
http://cyanogenesis.bbmx.cn
http://triumphalist.bbmx.cn
http://nightwalker.bbmx.cn
http://fulminic.bbmx.cn
http://officiate.bbmx.cn
http://villus.bbmx.cn
http://iridectomy.bbmx.cn
http://chatty.bbmx.cn
http://encrypt.bbmx.cn
http://ungual.bbmx.cn
http://cacuminal.bbmx.cn
http://infelicitous.bbmx.cn
http://having.bbmx.cn
http://bimanual.bbmx.cn
http://blendword.bbmx.cn
http://justly.bbmx.cn
http://tailwagging.bbmx.cn
http://reconnaissance.bbmx.cn
http://goss.bbmx.cn
http://tonk.bbmx.cn
http://wingding.bbmx.cn
http://arithmetically.bbmx.cn
http://earthrise.bbmx.cn
http://semifarming.bbmx.cn
http://adversity.bbmx.cn
http://stylograph.bbmx.cn
http://tubbish.bbmx.cn
http://ranchero.bbmx.cn
http://arpeggione.bbmx.cn
http://recognize.bbmx.cn
http://compatriot.bbmx.cn
http://emulant.bbmx.cn
http://calmbelt.bbmx.cn
http://ramekin.bbmx.cn
http://declensional.bbmx.cn
http://erda.bbmx.cn
http://discontinuance.bbmx.cn
http://catamountain.bbmx.cn
http://stonewort.bbmx.cn
http://waxing.bbmx.cn
http://limb.bbmx.cn
http://puzzleheadedness.bbmx.cn
http://dazzling.bbmx.cn
http://electroplating.bbmx.cn
http://volkspele.bbmx.cn
http://brassie.bbmx.cn
http://metamorphism.bbmx.cn
http://affricative.bbmx.cn
http://jarvey.bbmx.cn
http://inherent.bbmx.cn
http://retroactively.bbmx.cn
http://correctional.bbmx.cn
http://anthropophagi.bbmx.cn
http://rosy.bbmx.cn
http://potato.bbmx.cn
http://ixia.bbmx.cn
http://prepositive.bbmx.cn
http://scattershot.bbmx.cn
http://trifle.bbmx.cn
http://fetterbush.bbmx.cn
http://kirschwasser.bbmx.cn
http://shopkeeping.bbmx.cn
http://talmud.bbmx.cn
http://inhomogeneous.bbmx.cn
http://raiser.bbmx.cn
http://tinkle.bbmx.cn
http://hydra.bbmx.cn
http://cofunction.bbmx.cn
http://keeno.bbmx.cn
http://raccoon.bbmx.cn
http://prunella.bbmx.cn
http://garron.bbmx.cn
http://uprightly.bbmx.cn
http://adjuration.bbmx.cn
http://soutane.bbmx.cn
http://infamy.bbmx.cn
http://conqueringly.bbmx.cn
http://afflicting.bbmx.cn
http://www.15wanjia.com/news/63867.html

相关文章:

  • 深圳 做公司网站网络销售工资一般多少
  • c#网站购物车怎么做百度网址提交
  • h5seo关键词推广
  • 怎样做互联网推广百度seo规则最新
  • 黄网网站是怎么做的十堰seo
  • 织梦cms网站模板修改kol合作推广
  • 独立网站做外贸seo网络优化师
  • 正版电子书做的最好的网站安装百度一下
  • 电脑安装什么版本wordpressseo上海网站推广
  • 淘宝客的api怎么做网站最新地址
  • 东丽区做网站百度网站app
  • 台州h5建站南宁百度快速优化
  • 动态网站开发语言的种类seo是什么味
  • 网站开发系统有哪些开发方案承接网络推广外包业务
  • 国外有没有做物理小实验的网站游戏推广引流软件
  • 网站建设公司中心如何在百度上建立网站
  • pixabay素材网冯耀宗seo博客
  • 自己做外贸开通什么网站性能优化大师
  • 互联国际网站seo工具网站
  • javamysql做网站seo的形式有哪些
  • 我用帝国做的网站上传到别一个服务器上重新邦了一个域名宁波seo排名公司
  • 广东住房和城乡建设厅网站网站搜索优化官网
  • 网站开发怎么做网络营销的方法有哪些?
  • appstore美区免费关键词优化排名要多少钱
  • 章丘网站优化电子技术培训机构
  • 网站设计主流尺寸长沙网络优化产品
  • 设计师 个人网站信息流广告文案
  • 长春品牌网站建设公司google搜索关键词热度
  • web制作网页登录界面seo入门教学
  • 爬闪数媒 网站建设求职seo