From 95d133296b97bbdbc1cf63e265df489d7cd41113 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=A9=AC=E5=BA=9C=E5=BC=BA?=
<8569561+fuqiangma@user.noreply.gitee.com>
Date: Wed, 29 Nov 2023 21:11:36 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A0=91=E5=BD=A2=E6=95=B0=E6=8D=AE=E4=BC=98?=
=?UTF-8?q?=E9=9B=85=E7=BB=84=E8=A3=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
treenodedata/.idea/.gitignore | 8 ++
treenodedata/.idea/.name | 1 +
treenodedata/.idea/compiler.xml | 18 +++
treenodedata/.idea/encodings.xml | 6 +
treenodedata/.idea/jarRepositories.xml | 25 ++++
treenodedata/.idea/misc.xml | 11 ++
treenodedata/.idea/modules.xml | 9 ++
treenodedata/.idea/mybatisPlus.iml | 9 ++
treenodedata/.idea/uiDesigner.xml | 124 ++++++++++++++++++
treenodedata/mp-demo/mp-demo.iml | 8 ++
treenodedata/mp-demo/pom.xml | 110 ++++++++++++++++
.../java/com/woniu/mp/MpDemoApplication.java | 21 +++
.../mp/controller/CategoryController.java | 30 +++++
.../com/woniu/mp/entity/CategoryEntity.java | 71 ++++++++++
.../java/com/woniu/mp/mapper/CategoryDao.java | 12 ++
.../com/woniu/mp/mapstruct/first/Source.java | 10 ++
.../mapstruct/first/SourceTargetMapper.java | 24 ++++
.../com/woniu/mp/mapstruct/first/Target.java | 17 +++
.../mp/mapstruct/four/SimpleService.java | 10 ++
.../com/woniu/mp/mapstruct/four/Student.java | 9 ++
.../woniu/mp/mapstruct/four/StudentDto.java | 8 ++
.../mp/mapstruct/four/StudentMapper.java | 20 +++
.../woniu/mp/mapstruct/second/Customer.java | 10 ++
.../mp/mapstruct/second/CustomerDto.java | 15 +++
.../mp/mapstruct/second/CustomerMapper.java | 21 +++
.../mp/mapstruct/second/TimeAndFormat.java | 16 +++
.../com/woniu/mp/mapstruct/third/Bike.java | 22 ++++
.../com/woniu/mp/mapstruct/third/BikeDto.java | 21 +++
.../com/woniu/mp/mapstruct/third/Car.java | 17 +++
.../com/woniu/mp/mapstruct/third/CarDto.java | 17 +++
.../woniu/mp/mapstruct/third/ToEntity.java | 16 +++
.../mapstruct/third/TransportationMapper.java | 20 +++
.../com/woniu/mp/service/CategoryService.java | 18 +++
.../mp/service/impl/CategoryServiceImpl.java | 52 ++++++++
.../java/com/woniu/mp/util/MergeUtil.java | 24 ++++
.../src/main/java/com/woniu/mp/util/R.java | 56 ++++++++
.../src/main/resources/application.yaml | 16 +++
.../src/main/resources/mapper/UserMapper.xml | 5 +
.../com/woniu/mp/MpDemoApplicationTests.java | 12 ++
.../woniu/mp/mapper/TestTransactionTest.java | 69 ++++++++++
40 files changed, 988 insertions(+)
create mode 100644 treenodedata/.idea/.gitignore
create mode 100644 treenodedata/.idea/.name
create mode 100644 treenodedata/.idea/compiler.xml
create mode 100644 treenodedata/.idea/encodings.xml
create mode 100644 treenodedata/.idea/jarRepositories.xml
create mode 100644 treenodedata/.idea/misc.xml
create mode 100644 treenodedata/.idea/modules.xml
create mode 100644 treenodedata/.idea/mybatisPlus.iml
create mode 100644 treenodedata/.idea/uiDesigner.xml
create mode 100644 treenodedata/mp-demo/mp-demo.iml
create mode 100644 treenodedata/mp-demo/pom.xml
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/MpDemoApplication.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/controller/CategoryController.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/entity/CategoryEntity.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapper/CategoryDao.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Source.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/SourceTargetMapper.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Target.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/SimpleService.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/Student.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentDto.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentMapper.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/Customer.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerDto.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerMapper.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/TimeAndFormat.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Bike.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/BikeDto.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Car.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/CarDto.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/ToEntity.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/TransportationMapper.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/service/CategoryService.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/service/impl/CategoryServiceImpl.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/util/MergeUtil.java
create mode 100644 treenodedata/mp-demo/src/main/java/com/woniu/mp/util/R.java
create mode 100644 treenodedata/mp-demo/src/main/resources/application.yaml
create mode 100644 treenodedata/mp-demo/src/main/resources/mapper/UserMapper.xml
create mode 100644 treenodedata/mp-demo/src/test/java/com/woniu/mp/MpDemoApplicationTests.java
create mode 100644 treenodedata/mp-demo/src/test/java/com/woniu/mp/mapper/TestTransactionTest.java
diff --git a/treenodedata/.idea/.gitignore b/treenodedata/.idea/.gitignore
new file mode 100644
index 0000000..fb8a67e
--- /dev/null
+++ b/treenodedata/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/../../../:\mybatisPlus\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/treenodedata/.idea/.name b/treenodedata/.idea/.name
new file mode 100644
index 0000000..20a7d04
--- /dev/null
+++ b/treenodedata/.idea/.name
@@ -0,0 +1 @@
+mp-demo
\ No newline at end of file
diff --git a/treenodedata/.idea/compiler.xml b/treenodedata/.idea/compiler.xml
new file mode 100644
index 0000000..224fa0f
--- /dev/null
+++ b/treenodedata/.idea/compiler.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/encodings.xml b/treenodedata/.idea/encodings.xml
new file mode 100644
index 0000000..86b3a07
--- /dev/null
+++ b/treenodedata/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/jarRepositories.xml b/treenodedata/.idea/jarRepositories.xml
new file mode 100644
index 0000000..c4ded14
--- /dev/null
+++ b/treenodedata/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/misc.xml b/treenodedata/.idea/misc.xml
new file mode 100644
index 0000000..926ec49
--- /dev/null
+++ b/treenodedata/.idea/misc.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/modules.xml b/treenodedata/.idea/modules.xml
new file mode 100644
index 0000000..ed040c6
--- /dev/null
+++ b/treenodedata/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/mybatisPlus.iml b/treenodedata/.idea/mybatisPlus.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/treenodedata/.idea/mybatisPlus.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/.idea/uiDesigner.xml b/treenodedata/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/treenodedata/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/mp-demo/mp-demo.iml b/treenodedata/mp-demo/mp-demo.iml
new file mode 100644
index 0000000..1daccae
--- /dev/null
+++ b/treenodedata/mp-demo/mp-demo.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/treenodedata/mp-demo/pom.xml b/treenodedata/mp-demo/pom.xml
new file mode 100644
index 0000000..96e5006
--- /dev/null
+++ b/treenodedata/mp-demo/pom.xml
@@ -0,0 +1,110 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.6.7
+
+
+ com.woniu.mp
+ mp-demo
+ 0.0.1-SNAPSHOT
+ mp-demo
+ Demo project for Spring Boot
+
+ 1.8
+ 1.5.5.Final
+ 1.18.30
+
+
+
+ org.mapstruct
+ mapstruct
+ ${org.mapstruct.version}
+
+
+ org.mapstruct
+ mapstruct-processor
+ ${org.mapstruct.version}
+
+
+
+ org.projectlombok
+ lombok-mapstruct-binding
+ 0.2.0
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.30
+
+
+
+
+
+ io.springfox
+ springfox-swagger2
+ 2.9.2
+
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.9.2
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.0.5
+
+
+ cn.hutool
+ hutool-all
+ 5.8.11
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/MpDemoApplication.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/MpDemoApplication.java
new file mode 100644
index 0000000..68421b1
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/MpDemoApplication.java
@@ -0,0 +1,21 @@
+package com.woniu.mp;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ *
+ * 基于mybatisPlus的代码生成器插件
+ *
+ * @author woniu
+ * @since 2023-09-24
+ */
+@SpringBootApplication
+public class MpDemoApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(MpDemoApplication.class, args);
+ }
+
+}
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/controller/CategoryController.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/controller/CategoryController.java
new file mode 100644
index 0000000..0b2d051
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/controller/CategoryController.java
@@ -0,0 +1,30 @@
+package com.woniu.mp.controller;
+
+import cn.hutool.core.lang.tree.Tree;
+import com.woniu.mp.service.CategoryService;
+import com.woniu.mp.util.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+@RestController
+@RequestMapping("product/category")
+public class CategoryController {
+ @Autowired
+ private CategoryService categoryService;
+
+ /**
+ * 查询出所有分类以及子分类,以树形结构组装起来列表
+ */
+ @RequestMapping("/list/tree")
+ public R list(){
+ List> trees = categoryService.listWithTree();
+ return R.ok().put("data", trees);
+ }
+
+
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/entity/CategoryEntity.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/entity/CategoryEntity.java
new file mode 100644
index 0000000..810bf2e
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/entity/CategoryEntity.java
@@ -0,0 +1,71 @@
+package com.woniu.mp.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 商品三级分类
+ *
+ * @author 夏沫止水
+ * @email HeJieLin@gulimall.com
+ * @date 2020-05-22 19:00:18
+ */
+@Data
+@TableName("pms_category")
+public class CategoryEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 分类id
+ */
+ @TableId
+ private Long catId;
+ /**
+ * 分类名称
+ */
+ private String name;
+ /**
+ * 父分类id
+ */
+ private Long parentCid;
+ /**
+ * 层级
+ */
+ private Integer catLevel;
+ /**
+ * 是否显示[0-不显示,1显示]
+ */
+ @TableLogic(value = "1",delval = "0")
+ private Integer showStatus;
+ /**
+ * 排序
+ */
+ private Integer sort;
+ /**
+ * 图标地址
+ */
+ private String icon;
+ /**
+ * 计量单位
+ */
+ private String productUnit;
+ /**
+ * 商品数量
+ */
+ private Integer productCount;
+
+ /**
+ * 所有子分类
+ */
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ @TableField(exist = false)
+ private List children;
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapper/CategoryDao.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapper/CategoryDao.java
new file mode 100644
index 0000000..ec8b82e
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapper/CategoryDao.java
@@ -0,0 +1,12 @@
+package com.woniu.mp.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.woniu.mp.entity.CategoryEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+
+@Mapper
+public interface CategoryDao extends BaseMapper {
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Source.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Source.java
new file mode 100644
index 0000000..c2bbb2c
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Source.java
@@ -0,0 +1,10 @@
+package com.woniu.mp.mapstruct.first;
+
+import lombok.Data;
+
+@Data
+public class Source {
+ private String stringProp;
+ private Long longProp;
+}
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/SourceTargetMapper.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/SourceTargetMapper.java
new file mode 100644
index 0000000..ca64a68
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/SourceTargetMapper.java
@@ -0,0 +1,24 @@
+package com.woniu.mp.mapstruct.first;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
+
+/**
+ * mapstruct这么用,同事也纷纷模仿
+ * mapstruct几个常用小技巧
+ */
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
+public interface SourceTargetMapper {
+ /**
+ * 常量转换
+ */
+ @Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined")
+ @Mapping(target = "longProperty", source = "longProp", defaultValue = "-1l")
+ @Mapping(target = "stringConstant", constant = "Constant Value")
+ @Mapping(target = "integerConstant", constant = "14")
+ @Mapping(target = "longWrapperConstant", constant = "3001L")
+ @Mapping(target = "dateConstant", dateFormat = "yyyy-MM-dd", constant = "2023-09-01-")
+ Target sourceToTarget(Source s);
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Target.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Target.java
new file mode 100644
index 0000000..5e42e28
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/first/Target.java
@@ -0,0 +1,17 @@
+package com.woniu.mp.mapstruct.first;
+
+import lombok.Data;
+
+import java.util.Date;
+
+
+@Data
+public class Target {
+ private String stringProperty;
+ private long longProperty;
+ private String stringConstant;
+ private Integer integerConstant;
+ private Long longWrapperConstant;
+ private Date dateConstant;
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/SimpleService.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/SimpleService.java
new file mode 100644
index 0000000..60fc3b3
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/SimpleService.java
@@ -0,0 +1,10 @@
+package com.woniu.mp.mapstruct.four;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class SimpleService {
+ public String formatName(String name) {
+ return "您的名字是:" + name;
+ }
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/Student.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/Student.java
new file mode 100644
index 0000000..a9e8723
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/Student.java
@@ -0,0 +1,9 @@
+package com.woniu.mp.mapstruct.four;
+
+
+import lombok.Data;
+
+@Data
+public class Student {
+ private String name;
+}
\ No newline at end of file
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentDto.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentDto.java
new file mode 100644
index 0000000..78b427f
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentDto.java
@@ -0,0 +1,8 @@
+package com.woniu.mp.mapstruct.four;
+
+import lombok.Data;
+
+@Data
+public class StudentDto {
+ private String name;
+}
\ No newline at end of file
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentMapper.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentMapper.java
new file mode 100644
index 0000000..25e3e30
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/four/StudentMapper.java
@@ -0,0 +1,20 @@
+package com.woniu.mp.mapstruct.four;
+
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
+public abstract class StudentMapper {
+
+ @Autowired
+ protected SimpleService simpleService;
+
+ /**
+ * 转换的时候,如何注入springBean
+ */
+ @Mapping(target = "name", expression = "java(simpleService.formatName(source.getName()))")
+ public abstract Student map(StudentDto source);
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/Customer.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/Customer.java
new file mode 100644
index 0000000..53f32a0
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/Customer.java
@@ -0,0 +1,10 @@
+package com.woniu.mp.mapstruct.second;
+
+import lombok.Data;
+
+@Data
+public class Customer {
+ private String id;
+ private String name;
+ private TimeAndFormat timeAndFormat;
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerDto.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerDto.java
new file mode 100644
index 0000000..b3cc64a
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerDto.java
@@ -0,0 +1,15 @@
+package com.woniu.mp.mapstruct.second;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class CustomerDto {
+ public Long id;
+ public String customerName;
+
+ private String format;
+ private Date time;
+}
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerMapper.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerMapper.java
new file mode 100644
index 0000000..8c7da53
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/CustomerMapper.java
@@ -0,0 +1,21 @@
+package com.woniu.mp.mapstruct.second;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
+
+import java.util.UUID;
+
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, imports = UUID.class)
+public interface CustomerMapper {
+
+ /**
+ * 场景二:转换中调用表达式
+ */
+ @Mapping(target = "timeAndFormat",
+ expression = "java( new TimeAndFormat( s.getTime(), s.getFormat() ) )")
+ @Mapping(target = "id", source = "id", defaultExpression = "java( UUID.randomUUID().toString() )")
+ Customer toCustomer(CustomerDto s);
+
+}
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/TimeAndFormat.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/TimeAndFormat.java
new file mode 100644
index 0000000..03a5cf8
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/second/TimeAndFormat.java
@@ -0,0 +1,16 @@
+package com.woniu.mp.mapstruct.second;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class TimeAndFormat {
+ private Date time;
+ private String format;
+
+ public TimeAndFormat(Date time, String format) {
+ this.time = time;
+ this.format = format;
+ }
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Bike.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Bike.java
new file mode 100644
index 0000000..9490847
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Bike.java
@@ -0,0 +1,22 @@
+package com.woniu.mp.mapstruct.third;
+
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class Bike {
+ /**
+ * 唯一id
+ */
+ private String id;
+
+ private Date creationDate;
+
+ /**
+ * 品牌
+ */
+ private String brandName;
+
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/BikeDto.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/BikeDto.java
new file mode 100644
index 0000000..1e32947
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/BikeDto.java
@@ -0,0 +1,21 @@
+package com.woniu.mp.mapstruct.third;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class BikeDto {
+
+ /**
+ * 唯一id
+ */
+ private String id;
+
+ private Date creationDate;
+
+ /**
+ * 品牌
+ */
+ private String brand;
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Car.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Car.java
new file mode 100644
index 0000000..08eda00
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/Car.java
@@ -0,0 +1,17 @@
+package com.woniu.mp.mapstruct.third;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class Car {
+ /**
+ * 唯一id
+ */
+ private String id;
+
+ private Date creationDate;
+
+ private String otherName;
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/CarDto.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/CarDto.java
new file mode 100644
index 0000000..295c410
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/CarDto.java
@@ -0,0 +1,17 @@
+package com.woniu.mp.mapstruct.third;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class CarDto {
+ /**
+ * 唯一id
+ */
+ private String id;
+
+ private Date creationDate;
+
+ private String other;
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/ToEntity.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/ToEntity.java
new file mode 100644
index 0000000..b5b4398
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/ToEntity.java
@@ -0,0 +1,16 @@
+package com.woniu.mp.mapstruct.third;
+
+
+import org.mapstruct.Mapping;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+//通用注解
+@Retention(RetentionPolicy.CLASS)
+//自动生成当前日期
+@Mapping(target = "creationDate", expression = "java(new java.util.Date())")
+//忽略id
+@Mapping(target = "id", ignore = true)
+public @interface ToEntity {
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/TransportationMapper.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/TransportationMapper.java
new file mode 100644
index 0000000..cc1d144
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/mapstruct/third/TransportationMapper.java
@@ -0,0 +1,20 @@
+package com.woniu.mp.mapstruct.third;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
+
+
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
+public interface TransportationMapper {
+ /**
+ * 类共用属性,如何复用
+ */
+ @ToEntity
+ @Mapping( target = "brandName", source = "brand")
+ Bike map(BikeDto source);
+
+ @ToEntity
+ @Mapping( target = "otherName", source = "other")
+ Car map(CarDto source);
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/CategoryService.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/CategoryService.java
new file mode 100644
index 0000000..2a9ff39
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/CategoryService.java
@@ -0,0 +1,18 @@
+package com.woniu.mp.service;
+
+
+import cn.hutool.core.lang.tree.Tree;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.woniu.mp.entity.CategoryEntity;
+
+import java.util.List;
+
+public interface CategoryService extends IService {
+
+
+
+ List> listWithTree();
+
+
+}
+
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/impl/CategoryServiceImpl.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/impl/CategoryServiceImpl.java
new file mode 100644
index 0000000..80ffe5f
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/service/impl/CategoryServiceImpl.java
@@ -0,0 +1,52 @@
+package com.woniu.mp.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.core.lang.tree.TreeNode;
+import cn.hutool.core.lang.tree.TreeUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.woniu.mp.entity.CategoryEntity;
+import com.woniu.mp.mapper.CategoryDao;
+import com.woniu.mp.service.CategoryService;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+@Service("categoryService")
+public class CategoryServiceImpl extends ServiceImpl implements CategoryService {
+
+ /**
+ * 树形数据还可以这样组装?真优雅!
+ */
+ public List> listWithTree() {
+ List entities = baseMapper.selectList(null);
+ if (!CollectionUtil.isEmpty(entities)) {
+ List> list = entities.
+ stream().
+ map(CategoryServiceImpl::getLongTreeNode).
+ collect(Collectors.toList());
+ return TreeUtil.build(list, 0L);
+ }
+ return Collections.emptyList();
+ }
+
+ private static TreeNode getLongTreeNode(CategoryEntity item) {
+ TreeNode treeNode = new TreeNode<>();
+ treeNode.setId(item.getCatId());
+ treeNode.setParentId(item.getParentCid());
+ treeNode.setName(item.getName());
+ treeNode.setWeight(item.getSort());
+ Map extra = new HashMap<>();
+ extra.put("showStatus", item.getShowStatus());
+ extra.put("catLevel", item.getCatLevel());
+ extra.put("icon", item.getIcon());
+ extra.put("productUnit", item.getProductUnit());
+ extra.put("productCount", item.getProductCount());
+ treeNode.setExtra(extra);
+ return treeNode;
+ }
+
+
+}
\ No newline at end of file
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/MergeUtil.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/MergeUtil.java
new file mode 100644
index 0000000..7eebaeb
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/MergeUtil.java
@@ -0,0 +1,24 @@
+package com.woniu.mp.util;
+
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
+
+public class MergeUtil {
+ private static final CopyOptions options = CopyOptions.create().setIgnoreNullValue(true).setOverride(false);
+ private static final CopyOptions optionsAllowOverride = CopyOptions.create().setIgnoreNullValue(true).setOverride(true);
+
+ //将sourceBean中的属性合并到tagetBean,忽略Null值,非Null值不允许覆盖
+ public static Object merge(Object sourceBean, Object targetBean) {
+ BeanUtil.copyProperties(sourceBean, targetBean, options);
+
+ return targetBean;
+ }
+
+ //将sourceBean中的属性合并到tagetBean,忽略Null值,非Null值允许覆盖
+ public static Object mergeAllowOverride(Object sourceBean, Object targetBean) {
+ BeanUtil.copyProperties(sourceBean, targetBean, optionsAllowOverride);
+
+ return targetBean;
+ }
+}
diff --git a/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/R.java b/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/R.java
new file mode 100644
index 0000000..1e0923a
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/java/com/woniu/mp/util/R.java
@@ -0,0 +1,56 @@
+
+package com.woniu.mp.util;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class R extends HashMap {
+ private static final long serialVersionUID = 1L;
+
+ public R setData(Object data) {
+ put("data",data);
+ return this;
+ }
+
+
+ public R() {
+ put("code", 0);
+ put("msg", "success");
+ }
+
+ public static R error(int code, String msg) {
+ R r = new R();
+ r.put("code", code);
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(String msg) {
+ R r = new R();
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(Map map) {
+ R r = new R();
+ r.putAll(map);
+ return r;
+ }
+
+ public static R ok() {
+ return new R();
+ }
+
+ public R put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+
+ public Integer getCode() {
+
+ return (Integer) this.get("code");
+ }
+
+}
diff --git a/treenodedata/mp-demo/src/main/resources/application.yaml b/treenodedata/mp-demo/src/main/resources/application.yaml
new file mode 100644
index 0000000..1a9a975
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/resources/application.yaml
@@ -0,0 +1,16 @@
+spring:
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ username: root
+ password: 123456
+ hikari:
+ #最大连接数量,默认10
+ maximum-pool-size: 1
+logging:
+ level:
+ com.itheima: debug
+ pattern:
+ dateformat: HH:mm:ss
+mybatis:
+ mapper-locations: classpath*:mapper/*.xml
diff --git a/treenodedata/mp-demo/src/main/resources/mapper/UserMapper.xml b/treenodedata/mp-demo/src/main/resources/mapper/UserMapper.xml
new file mode 100644
index 0000000..4b87e13
--- /dev/null
+++ b/treenodedata/mp-demo/src/main/resources/mapper/UserMapper.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/treenodedata/mp-demo/src/test/java/com/woniu/mp/MpDemoApplicationTests.java b/treenodedata/mp-demo/src/test/java/com/woniu/mp/MpDemoApplicationTests.java
new file mode 100644
index 0000000..4ce36a1
--- /dev/null
+++ b/treenodedata/mp-demo/src/test/java/com/woniu/mp/MpDemoApplicationTests.java
@@ -0,0 +1,12 @@
+package com.woniu.mp;
+
+import org.junit.jupiter.api.Test;
+
+class MpDemoApplicationTests {
+
+ @Test
+ void contextLoads() {
+
+ }
+
+}
diff --git a/treenodedata/mp-demo/src/test/java/com/woniu/mp/mapper/TestTransactionTest.java b/treenodedata/mp-demo/src/test/java/com/woniu/mp/mapper/TestTransactionTest.java
new file mode 100644
index 0000000..775d6f5
--- /dev/null
+++ b/treenodedata/mp-demo/src/test/java/com/woniu/mp/mapper/TestTransactionTest.java
@@ -0,0 +1,69 @@
+package com.woniu.mp.mapper;
+
+
+import com.woniu.mp.mapstruct.first.Source;
+import com.woniu.mp.mapstruct.first.SourceTargetMapper;
+import com.woniu.mp.mapstruct.first.Target;
+
+import com.woniu.mp.mapstruct.second.Customer;
+import com.woniu.mp.mapstruct.second.CustomerDto;
+import com.woniu.mp.mapstruct.second.CustomerMapper;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+@SpringBootTest
+class TestTransactionTest {
+ @Resource
+ TestTransaction testTransaction;
+
+ @Resource
+ SourceTargetMapper targetMapper;
+
+ @Resource
+ CustomerMapper customerMapper;
+
+
+
+ /**
+ * 常量转换
+ */
+ @Test
+ void testFirst() {
+ Source source = new Source();
+ source.setLongProp(1l);
+ source.setStringProp("woniu");
+ Target target = targetMapper.sourceToTarget(source);
+ System.out.println(target);
+ }
+
+ /**
+ * 转换中调用表达式
+ */
+ @Test
+ void testSecond() {
+ CustomerDto customerDto = new CustomerDto();
+ customerDto.setId(1L);
+ customerDto.setTime(new Date());
+ customerDto.setCustomerName("woniu");
+ customerDto.setFormat("yyyy-MM");
+ Customer customer = customerMapper.toCustomer(customerDto);
+ System.out.println(customer);
+ }
+
+ @Test
+ void testThird() {
+ CustomerDto customerDto = new CustomerDto();
+ customerDto.setId(1L);
+ customerDto.setTime(new Date());
+ customerDto.setCustomerName("woniu");
+ customerDto.setFormat("yyyy-MM");
+ Customer customer = customerMapper.toCustomer(customerDto);
+ System.out.println(customer);
+ }
+
+
+
+}