Compare commits

...

1 Commits
master ... a1

Author SHA1 Message Date
31353 fac0fb5d5e 第二次提交 2023-12-23 10:15:14 +08:00
11 changed files with 264 additions and 1 deletions

View File

@ -0,0 +1,19 @@
package com.bwie.common.domain;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author gxb
* @description TODO
* @date 2023-12-23 10:12
*/
@Data
public class Trees {
private Integer id;
private Integer treesId;
private String treesName;
private List<Trees> children = new ArrayList<>();
}

View File

@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bwie</groupId>
<artifactId>Java-Heathl</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>bwie-trees</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.bwie</groupId>
<artifactId>bwie-common</artifactId>
</dependency>
<!-- SpringBoot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package com.bwie.trees;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class TreesApplication{
public static void main(String[] args) {
SpringApplication.run(TreesApplication.class,args);
}
}

View File

@ -0,0 +1,36 @@
package com.bwie.trees.controller;
import com.bwie.common.domain.Trees;
import com.bwie.common.result.Result;
import com.bwie.trees.service.TreesService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@RestController
@Log4j2
@RequestMapping("/tress")
public class TreesController{
@Autowired
private TreesService treesService;
@Autowired
private HttpServletRequest request;
@PostMapping("/selectOne")
public Result<List<Trees>> Select(){
return treesService.treesSelect();
}
// @PostMapping("/SelectOne")
// public Result<List<Trees>> SelectOne(){
// return treesService.treesSelectOne();
// }
@PostMapping("/selectTwo")
public Result<List<Trees>> SelectTwo(){
return treesService.treesSelectTwo();
}
}

View File

@ -0,0 +1,12 @@
package com.bwie.trees.mapper;
import com.bwie.common.domain.Trees;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface TreesMapper{
List<Trees> treesSelect();
}

View File

@ -0,0 +1,15 @@
package com.bwie.trees.service;
import com.bwie.common.domain.Trees;
import com.bwie.common.result.Result;
import java.util.List;
public interface TreesService{
Result<List<Trees>> treesSelect();
// Result<List<Trees>> treesSelectOne();
Result<List<Trees>> treesSelectTwo();
}

View File

@ -0,0 +1,64 @@
package com.bwie.trees.service.impl;
import com.bwie.common.domain.Trees;
import com.bwie.common.result.Result;
import com.bwie.trees.mapper.TreesMapper;
import com.bwie.trees.service.TreesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class TreesServiceImpl implements TreesService{
@Autowired
private TreesMapper treesMapper;
@Override/*1.查询表*/
public Result<List<Trees>> treesSelect() {
List<Trees> list = treesMapper.treesSelect();
return Result.success(list,"查询成功");
}
// @Override
// public Result<List<Trees>> treesSelectOne() {
// Result<List<Trees>> listResult = this.treesSelect();
// List<Trees> treesList = listResult.getData();
// List<Trees> collect = treesList.stream().
// filter(trees -> trees.getTreesId() == 0).
// peek(trees -> trees.setChildren(getChildren(trees,treesList).isEmpty() ? null : getChildren(trees,treesList))).
// sorted().
// collect(Collectors.toList());
// return Result.success(collect);
// }
@Override
public Result<List<Trees>> treesSelectTwo() {
Result<List<Trees>> listResult = this.treesSelect();
List<Trees> treesList = listResult.getData();
List<Trees> collect = treesList
.stream()
.filter(trees -> trees.getTreesId() == 0)
.peek(trees -> trees.setChildren(getChildren(trees, treesList).isEmpty() ? null : getChildren(trees,treesList)))
.collect(Collectors.toList());
return Result.success(collect);
}
private List<Trees> getChildren(Trees tree, List<Trees> treesList){
List<Trees> collect = treesList.stream()//转Stream型
.filter(trees -> trees.getTreesId() == tree.getId())//过滤父类ID是否等于主键ID
.peek(trees -> trees.setChildren(getChildren(trees, treesList).isEmpty() ? null : getChildren(trees, treesList)))//给属性设置
.collect(Collectors.toList());
return collect;
}
// private List<Trees> getCidrens(//对象 ,//list集合)
// {
// 将list集合转stream
// .filter来进行一个过滤
// .peek设置属性
// .collect存入list
// }
}

View File

@ -0,0 +1,43 @@
# Tomcat
server:
port: 9005
# Spring
spring:
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: bwie-trees
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地
server-addr: 124.221.211.96:8848
config:
# 配置中心地址
server-addr: 124.221.211.96:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
fdfs:
so-timeout: 1500 # socket 连接时长
connect-timeout: 600 # 连接 tracker 服务器超时时长
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
tracker-list: 124.221.211.96:22122
web-server-url: 124.221.211.96:8888
pool:
jmx-enabled: false
# 生成缩略图
thumb-image:
height: 500
width: 500

View File

@ -0,0 +1,9 @@
<?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.bwie.trees.mapper.TreesMapper">
<select id="treesSelect" resultType="com.bwie.common.domain.Trees">
select * from trees
</select>
</mapper>

View File

@ -13,6 +13,8 @@
<packaging>pom</packaging>
<modules>
<module>bwie-health</module>
<module>bwie-trees</module>
</modules>
<properties>
@ -21,4 +23,4 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
</project>