From cf267cf0ca470ebcf54b8e34a905930639afed14 Mon Sep 17 00:00:00 2001
From: xuwujing <1060589146@qq.com>
Date: Mon, 15 Jan 2024 15:42:24 +0800
Subject: [PATCH] add springboot-demo
---
springboot-demo/README.md | 40 +++
springboot-demo/build-dev.bat | 1 +
springboot-demo/build-dev.xml | 55 +++
springboot-demo/db/pcm.sql | 42 +++
springboot-demo/easycode/EasyCodeConfig.json | 69 ++++
springboot-demo/git-info.bat | 13 +
springboot-demo/pom.xml | 223 ++++++++++++
.../src/main/java/com/pancm/Application.java | 40 +++
.../java/com/pancm/config/CorsFilter.java | 49 +++
.../com/pancm/config/PancmConfiguration.java | 120 +++++++
.../com/pancm/config/SpringBeanFactory.java | 50 +++
.../java/com/pancm/config/SwaggerConfig.java | 64 ++++
.../com/pancm/controller/HomeController.java | 53 +++
.../com/pancm/controller/UserController.java | 103 ++++++
.../src/main/java/com/pancm/dao/UserDao.java | 86 +++++
.../src/main/java/com/pancm/model/User.java | 71 ++++
.../java/com/pancm/service/IUserService.java | 60 ++++
.../pancm/service/impl/UserServiceImpl.java | 96 ++++++
.../main/java/com/pancm/util/FileHelper.java | 321 ++++++++++++++++++
.../java/com/pancm/util/GetProperties.java | 94 +++++
.../src/main/java/com/pancm/vo/ApiResult.java | 92 +++++
.../main/java/com/pancm/vo/BaseConstants.java | 42 +++
.../src/main/java/com/pancm/vo/BasePage.java | 74 ++++
.../main/java/com/pancm/vo/PageResult.java | 30 ++
.../src/main/java/com/pancm/vo/UserVO.java | 71 ++++
.../src/main/resources/application-dev.yml | 14 +
.../src/main/resources/application-local.yml | 14 +
.../src/main/resources/application.yml | 5 +
.../src/main/resources/build.properties | 4 +
.../src/main/resources/logback.xml | 79 +++++
.../pancm/mapper/DbVersionMapper.xml | 8 +
.../resources/pancm/mapper/UserMapper.xml | 148 ++++++++
.../main/resources/pancm/mybatis-config.xml | 15 +
.../src/main/resources/version.txt | 1 +
springboot-demo/start.sh | 11 +
springboot-demo/stop.sh | 13 +
36 files changed, 2271 insertions(+)
create mode 100644 springboot-demo/README.md
create mode 100644 springboot-demo/build-dev.bat
create mode 100644 springboot-demo/build-dev.xml
create mode 100644 springboot-demo/db/pcm.sql
create mode 100644 springboot-demo/easycode/EasyCodeConfig.json
create mode 100644 springboot-demo/git-info.bat
create mode 100644 springboot-demo/pom.xml
create mode 100644 springboot-demo/src/main/java/com/pancm/Application.java
create mode 100644 springboot-demo/src/main/java/com/pancm/config/CorsFilter.java
create mode 100644 springboot-demo/src/main/java/com/pancm/config/PancmConfiguration.java
create mode 100644 springboot-demo/src/main/java/com/pancm/config/SpringBeanFactory.java
create mode 100644 springboot-demo/src/main/java/com/pancm/config/SwaggerConfig.java
create mode 100644 springboot-demo/src/main/java/com/pancm/controller/HomeController.java
create mode 100644 springboot-demo/src/main/java/com/pancm/controller/UserController.java
create mode 100644 springboot-demo/src/main/java/com/pancm/dao/UserDao.java
create mode 100644 springboot-demo/src/main/java/com/pancm/model/User.java
create mode 100644 springboot-demo/src/main/java/com/pancm/service/IUserService.java
create mode 100644 springboot-demo/src/main/java/com/pancm/service/impl/UserServiceImpl.java
create mode 100644 springboot-demo/src/main/java/com/pancm/util/FileHelper.java
create mode 100644 springboot-demo/src/main/java/com/pancm/util/GetProperties.java
create mode 100644 springboot-demo/src/main/java/com/pancm/vo/ApiResult.java
create mode 100644 springboot-demo/src/main/java/com/pancm/vo/BaseConstants.java
create mode 100644 springboot-demo/src/main/java/com/pancm/vo/BasePage.java
create mode 100644 springboot-demo/src/main/java/com/pancm/vo/PageResult.java
create mode 100644 springboot-demo/src/main/java/com/pancm/vo/UserVO.java
create mode 100644 springboot-demo/src/main/resources/application-dev.yml
create mode 100644 springboot-demo/src/main/resources/application-local.yml
create mode 100644 springboot-demo/src/main/resources/application.yml
create mode 100644 springboot-demo/src/main/resources/build.properties
create mode 100644 springboot-demo/src/main/resources/logback.xml
create mode 100644 springboot-demo/src/main/resources/pancm/mapper/DbVersionMapper.xml
create mode 100644 springboot-demo/src/main/resources/pancm/mapper/UserMapper.xml
create mode 100644 springboot-demo/src/main/resources/pancm/mybatis-config.xml
create mode 100644 springboot-demo/src/main/resources/version.txt
create mode 100644 springboot-demo/start.sh
create mode 100644 springboot-demo/stop.sh
diff --git a/springboot-demo/README.md b/springboot-demo/README.md
new file mode 100644
index 0000000..4d9bdb4
--- /dev/null
+++ b/springboot-demo/README.md
@@ -0,0 +1,40 @@
+## springBoot-demo
+
+springBoot-demo 是一个SpringBoot的基础框架项目,可以在此项目上进行扩展。
+
+## 开发环境
+
+- Java 8+
+- Maven 3.5.4+
+- SpringBoot 2.3.12.RELEASE
+- mysql5.7+
+- ant1.9+ (非必须,打包可用)
+
+
+## 快速开始
+
+**使用**
+
+- git clone https://github.com/xuwujing/springBoot-study/springBoot-demo.git
+
+**使用**
+
+秉着开箱即用的原则,更改相应的配置(MySql、Es、Redis等地址配置),运行main方法,即可启动!
+
+**注意**
+
+ EasyCode模板生成的xml若是没有逗号,则需要将全局模版velocityHasNext修改为foreach.hasNext。
+
+## 项目结构
+
+```
+springBoot-demo
+├── pom.xml
+├── README.md
+├── build-dev.xml
+├── README.md
+└── src
+ ├── main
+ │ ├── java
+ │ │ └── com
+ │ │ └── pancm
\ No newline at end of file
diff --git a/springboot-demo/build-dev.bat b/springboot-demo/build-dev.bat
new file mode 100644
index 0000000..3178c7c
--- /dev/null
+++ b/springboot-demo/build-dev.bat
@@ -0,0 +1 @@
+ant -f build-dev.xml
\ No newline at end of file
diff --git a/springboot-demo/build-dev.xml b/springboot-demo/build-dev.xml
new file mode 100644
index 0000000..abf9d50
--- /dev/null
+++ b/springboot-demo/build-dev.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/springboot-demo/db/pcm.sql b/springboot-demo/db/pcm.sql
new file mode 100644
index 0000000..83bc610
--- /dev/null
+++ b/springboot-demo/db/pcm.sql
@@ -0,0 +1,42 @@
+/*
+ Navicat Premium Data Transfer
+
+ Source Server : 本地-mysql
+ Source Server Type : MySQL
+ Source Server Version : 50744
+ Source Host : localhost:3306
+ Source Schema : pcm
+
+ Target Server Type : MySQL
+ Target Server Version : 50744
+ File Encoding : 65001
+
+ Date: 15/01/2024 15:40:52
+*/
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for user
+-- ----------------------------
+DROP TABLE IF EXISTS `user`;
+CREATE TABLE `user` (
+ `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '姓名',
+ `sex` tinyint(1) NULL DEFAULT 1 COMMENT '性别',
+ `age` int(4) NULL DEFAULT NULL COMMENT '年龄',
+ `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
+ `create_by` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
+ `update_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ `update_by` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户表' ROW_FORMAT = Dynamic;
+
+-- ----------------------------
+-- Records of user
+-- ----------------------------
+INSERT INTO `user` VALUES (1, '张三', 1, 18, '2020-02-15 14:35:46', 'admin', '2021-01-15 14:36:28', 'admin');
+INSERT INTO `user` VALUES (2, '小红', 2, 26, '2022-02-16 14:36:10', 'admin', '2021-01-15 14:36:39', 'admin');
+
+SET FOREIGN_KEY_CHECKS = 1;
diff --git a/springboot-demo/easycode/EasyCodeConfig.json b/springboot-demo/easycode/EasyCodeConfig.json
new file mode 100644
index 0000000..a176c05
--- /dev/null
+++ b/springboot-demo/easycode/EasyCodeConfig.json
@@ -0,0 +1,69 @@
+{
+ "author" : "pancm",
+ "version" : "1.2.8",
+ "userSecure" : "",
+ "currTypeMapperGroupName" : "Default",
+ "currTemplateGroupName" : "pancm",
+ "currColumnConfigGroupName" : "Default",
+ "currGlobalConfigGroupName" : "Default",
+ "typeMapper" : { },
+ "template" : {
+ "pancm" : {
+ "name" : "pancm",
+ "elementList" : [ {
+ "name" : "controller.java",
+ "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Controller\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/controller\"))\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;\n\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;\nimport org.springframework.web.bind.annotation.*;\n\n\nimport com.pancm.vo.ApiResult;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport javax.servlet.http.HttpServletRequest;\n\n\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表控制层\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Api(tags = \"$!{tableInfo.comment}($!{tableInfo.name})\")\n@RestController\n@RequestMapping(\"$!tool.firstLowerCase($tableInfo.name)\")\npublic class $!{tableName} {\n /**\n * 服务对象\n */\n @Autowired\n private I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;\n\n\n /**\n * 新增一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}新增\",notes = \"$!{tableInfo.comment}新增\")\n @RequestMapping(value = \"save\", method = RequestMethod.POST)\n public ApiResult insert(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n int result = $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name)VO);\n if (result > 0) {\n return ApiResult.success();\n }\n return ApiResult.error(\"新增失败\");\n }\n\n /**\n * 修改一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}修改\",notes = \"$!{tableInfo.comment}修改\")\n @RequestMapping(value = \"edit\", method = RequestMethod.POST)\n public ApiResult update(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n $!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name)VO); \n return ApiResult.success();\n }\n\n /**\n * 删除一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 参数对象\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}删除\",notes = \"$!{tableInfo.comment}删除\") \n @RequestMapping(value = \"del\", method = RequestMethod.POST)\n public ApiResult delete(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!{tool.firstLowerCase($tableInfo.name)}VO.getId());\n return ApiResult.success(); \n }\n\n \n\n /**\n * 分页查询\n *\n */\n @ApiOperation(value = \"$!{tableInfo.comment}查询\",notes = \"$!{tableInfo.comment}查询\")\n @RequestMapping(value = \"list\", method = RequestMethod.POST)\n public ApiResult list(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.list($!tool.firstLowerCase($tableInfo.name)VO);\n }\n\n /**\n * 详情查询\n *\n */ \n @ApiOperation(value = \"$!{tableInfo.comment}详情\",notes = \"$!{tableInfo.comment}详情\") \n @RequestMapping(value = \"view\", method = RequestMethod.GET)\n public ApiResult view( @RequestParam(\"id\") Long id) {\n return ApiResult.success($!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id)); \n }\n}"
+ }, {
+ "name" : "service.java",
+ "code" : "##定义初始变量\n#set($tableName = $tool.append(\"I\",$tableInfo.name, \"Service\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;\n$!autoImport\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport com.pancm.vo.ApiResult;\nimport java.util.List;\n\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务接口\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name);\n\n \n /**\n * 通过实体作为筛选条件查询\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n ApiResult list($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n boolean deleteById($!pk.shortType $!pk.name);\n\n}"
+ }, {
+ "name" : "serviceImpl.java",
+ "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"ServiceImpl\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service/impl\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;\n$!autoImport\n\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport $!{tableInfo.savePackageName}.model.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;\nimport $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;\n\nimport com.github.pagehelper.Page;\nimport com.github.pagehelper.PageHelper;\nimport com.pancm.vo.ApiResult;\nimport com.pancm.vo.PageResult;\nimport org.springframework.stereotype.Service;\nimport org.springframework.beans.BeanUtils;\nimport javax.annotation.Resource;\nimport java.util.List;\n\n\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务实现类\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Service(\"$!tool.firstLowerCase($!{tableInfo.name})Service\")\npublic class $!{tableName} implements I$!{tableInfo.name}Service {\n @Resource\n private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name) {\n return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name);\n }\n\n \n /**\n * 根据条件查询\n *\n * @return 实例对象的集合\n */\n @Override\n public ApiResult list($!{tableInfo.name}VO $!{tool.firstLowerCase($!{tableInfo.name})}) {\n int pageNum = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageNum();\n int pageSize = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageSize();\n Page page = PageHelper.startPage(pageNum, pageSize);\n List<$!{tableInfo.name}VO> result = $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryAll($!{tool.firstLowerCase($!{tableInfo.name})});\n return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum));\n \n }\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n @Override\n public int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {\n $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();\n BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));\n return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));\n }\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n @Override\n public int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {\n $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();\n BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));\n return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.update($!tool.firstLowerCase($!{tableInfo.name}));\n }\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n @Override\n public boolean deleteById($!pk.shortType $!pk.name) {\n return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name) > 0;\n }\n}"
+ }, {
+ "name" : "dao.java",
+ "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Dao\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/dao\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;\n\nimport $!{tableInfo.savePackageName}.model.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport org.apache.ibatis.annotations.Param;\nimport org.apache.ibatis.annotations.Mapper;\nimport java.util.List;\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Mapper\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name);\n\n \n /**\n * 通过实体查询一条数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n $!{tableInfo.name}VO findOne($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 通过实体作为筛选条件查询\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n List<$!{tableInfo.name}VO> queryAll($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 批量新增或按主键更新数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertOrUpdateBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 影响行数\n */\n int deleteById($!pk.shortType $!pk.name);\n\n}\n"
+ }, {
+ "name" : "vo.java",
+ "code" : "##引入宏定义\n$!define\n#set($tableName = $tool.append($tableInfo.name, \"VO\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/vo\"))\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}vo;\n##使用全局变量实现默认包导入\n$!autoImport\nimport java.io.Serializable;\nimport com.alibaba.fastjson.JSONObject;\nimport io.swagger.annotations.ApiModel;\nimport io.swagger.annotations.ApiModelProperty;\nimport lombok.Data;\nimport java.sql.Date;\nimport com.pancm.vo.BasePage;\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})请求响应对象\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@ApiModel(value = \"$!{tableInfo.name}\", description = \"$!{tableInfo.comment}\")\n@Data\npublic class $!{tableInfo.name}VO extends BasePage implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n /**\n * ${column.comment}\n */\n #end\n @ApiModelProperty(value = \"${column.comment}\")\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n #end\n\n\n\n @Override\n public String toString(){\n return JSONObject.toJSONString(this);\n }\n\n}"
+ }, {
+ "name" : "model.java",
+ "code" : "\n##导入宏定义\n$!{define.vm}\n\n##保存文件(宏定义)\n#save(\"/model\", \".java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"model\")\n\n\nimport com.alibaba.fastjson.JSONObject;\nimport lombok.Data;\n\nimport javax.persistence.Column;\nimport javax.persistence.Table;\nimport java.io.Serializable;\nimport java.sql.Date;\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})实体类\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Data\n@Table(name = \"$tableInfo.obj.name\")\npublic class $!{tableInfo.name} implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n /**\n * ${column.comment}\n */\n #end\n @Column(name = \"$column.obj.name\")\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n\n\n @Override\n public String toString(){\n return JSONObject.toJSONString(this);\n }\n\n}"
+ }, {
+ "name" : "mapper.xml.vm",
+ "code" : "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Mapper.xml\"))\n$!callback.setSavePath($tool.append($modulePath, \"/src/main/resources/pancm/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n\n\n\n\n \n#foreach($column in $tableInfo.fullColumn)\n \n#end\n \n\n \n \n \n \n \n\n \n \n\n \n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($foreach.hasNext), #end#end)\n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n on duplicate key update\n #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($foreach.hasNext), #end#end\n \n\n \n \n update $!{tableInfo.obj.name}\n \n#foreach($column in $tableInfo.otherColumn)\n \n $!column.obj.name = #{$!column.name},\n \n#end\n \n where $!pk.obj.name = #{$!pk.name}\n \n\n \n \n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}\n \n\n\n"
+ } ]
+ }
+ },
+ "columnConfig" : {
+ "Default" : {
+ "name" : "Default",
+ "elementList" : [ {
+ "title" : "disable",
+ "type" : "BOOLEAN",
+ "selectValue" : ""
+ }, {
+ "title" : "support",
+ "type" : "SELECT",
+ "selectValue" : "add,edit,query,del,ui"
+ } ]
+ }
+ },
+ "globalConfig" : {
+ "Default" : {
+ "name" : "Default",
+ "elementList" : [ {
+ "name" : "autoImport.vm",
+ "value" : "##自动导入包(仅导入实体属性需要的包,通常用于实体类)\n#foreach($import in $importList)\nimport $!import;\n#end"
+ }, {
+ "name" : "define.vm",
+ "value" : "##(Velocity宏定义)\n\n##定义设置表名后缀的宏定义,调用方式:#setTableSuffix(\"Test\")\n#macro(setTableSuffix $suffix)\n #set($tableName = $!tool.append($tableInfo.name, $suffix))\n#end\n\n##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix(\"Test\")\n#macro(setPackageSuffix $suffix)\n#if($suffix!=\"\")package #end#if($tableInfo.savePackageName!=\"\")$!{tableInfo.savePackageName}.#{end}$!suffix;\n#end\n\n##定义直接保存路径与文件名简化的宏定义,调用方式:#save(\"/entity\", \".java\")\n#macro(save $path $fileName)\n $!callback.setSavePath($tool.append($tableInfo.savePath, $path))\n $!callback.setFileName($tool.append($tableInfo.name, $fileName))\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.comment}($!{tableInfo.name})$desc\n *\n * @author $!author\n * @since $!time.currTime()\n */\n#end\n\n##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)\n#macro(getSetMethod $column)\n\n public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {\n return $!{column.name};\n }\n\n public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {\n this.$!{column.name} = $!{column.name};\n }\n#end"
+ }, {
+ "name" : "init.vm",
+ "value" : "##初始化区域\n\n##去掉表的t_前缀\n$!tableInfo.setName($tool.getClassName($tableInfo.obj.name.replaceFirst(\"book_\",\"\")))\n\n##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误\n#foreach($column in $tableInfo.fullColumn)\n#if($column.name.startsWith(\"is\") && $column.type.equals(\"java.lang.Boolean\"))\n $!column.setName($tool.firstLowerCase($column.name.substring(2)))\n#end\n#end\n\n##实现动态排除列\n#set($temp = $tool.newHashSet(\"testCreateTime\", \"otherColumn\"))\n#foreach($item in $temp)\n #set($newList = $tool.newArrayList())\n #foreach($column in $tableInfo.fullColumn)\n #if($column.name!=$item)\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($newList.add($column))\n #end\n #end\n ##重新保存\n $tableInfo.setFullColumn($newList)\n#end\n\n##对importList进行篡改\n#set($temp = $tool.newHashSet())\n#foreach($column in $tableInfo.fullColumn)\n #if(!$column.type.startsWith(\"java.lang.\"))\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($temp.add($column.type))\n #end\n#end\n##覆盖\n#set($importList = $temp)"
+ }, {
+ "name" : "mybatisSupport.vm",
+ "value" : "##针对Mybatis 进行支持,主要用于生成xml文件\n#foreach($column in $tableInfo.fullColumn)\n ##储存列类型\n $tool.call($column.ext.put(\"sqlType\", $tool.getField($column.obj.dataType, \"typeName\")))\n #if($tool.newHashSet(\"java.lang.String\").contains($column.type))\n #set($jdbcType=\"VARCHAR\")\n #elseif($tool.newHashSet(\"java.lang.Boolean\", \"boolean\").contains($column.type))\n #set($jdbcType=\"BOOLEAN\")\n #elseif($tool.newHashSet(\"java.lang.Byte\", \"byte\").contains($column.type))\n #set($jdbcType=\"BYTE\")\n #elseif($tool.newHashSet(\"java.lang.Integer\", \"int\", \"java.lang.Short\", \"short\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Long\", \"long\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Float\", \"float\", \"java.lang.Double\", \"double\").contains($column.type))\n #set($jdbcType=\"NUMERIC\")\n #elseif($tool.newHashSet(\"java.util.Date\", \"java.sql.Timestamp\", \"java.time.Instant\", \"java.time.LocalDateTime\", \"java.time.OffsetDateTime\", \"\tjava.time.ZonedDateTime\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #elseif($tool.newHashSet(\"java.sql.Date\", \"java.time.LocalDate\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #else\n ##其他类型\n #set($jdbcType=\"VARCHAR\")\n #end\n $tool.call($column.ext.put(\"jdbcType\", $jdbcType))\n#end\n\n##定义宏,查询所有列\n#macro(allSqlColumn)#foreach($column in $tableInfo.fullColumn)$column.obj.name#if($foreach.hasNext), #end#end#end\n"
+ } ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/springboot-demo/git-info.bat b/springboot-demo/git-info.bat
new file mode 100644
index 0000000..abc88de
--- /dev/null
+++ b/springboot-demo/git-info.bat
@@ -0,0 +1,13 @@
+@echo off
+set time=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
+set app=springboot-demo
+for /F %%i in ('git rev-parse --short HEAD') do ( set commit_id=%%i)
+for /F %%i in ('git rev-parse --abbrev-ref HEAD') do ( set branch_id=%%i)
+echo build_app = %app% > ./src/main/resources/build.properties
+echo build_time = %time% >> ./src/main/resources/build.properties
+echo git_commit = %commit_id% >> ./src/main/resources/build.properties
+echo git_branch = %branch_id% >> ./src/main/resources/build.properties
+echo start %app% at %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
+::echo "build_version = '${version}'" > ./src/main/resources/build.properties
+::echo "upload %app%"
+::echo "done %app% %time% at $(date "+%Y-%m-%d %H:%M:%S")"
diff --git a/springboot-demo/pom.xml b/springboot-demo/pom.xml
new file mode 100644
index 0000000..bdf7928
--- /dev/null
+++ b/springboot-demo/pom.xml
@@ -0,0 +1,223 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.13.RELEASE
+
+
+ com.zans
+ springboot-demo
+ 0.0.1-SNAPSHOT
+ springboot-demo
+ Demo project for Spring Boot
+
+
+ 1.8
+ 1.7.25
+ 1.2.3
+ 3.5.0
+ 2.6.2
+ 2.9.2
+ 1.5.21
+ 1.9.6
+ 1.2.62
+ 5.1.41
+ 1.1.12
+ 4.0.3
+ 1.3.1
+ 1.1.4
+ 2.9.2
+ 1.5.21
+ 1.9.6
+
+
+
+
+
+ local
+
+ local
+
+
+
+ true
+
+
+
+
+ dev
+
+ dev
+
+
+
+
+ prod
+
+ prod
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ org.apache.tomcat
+ tomcat-jdbc
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+ mysql
+ mysql-connector-java
+ ${mysql.connector.version}
+
+
+ com.alibaba
+ druid
+ ${alibaba.druid.version}
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ ${mybatis.spring.boot.version}
+
+
+ tk.mybatis
+ mapper-spring-boot-starter
+ ${tk.mybatis.boot.version}
+
+
+
+ org.mybatis.generator
+ mybatis-generator-core
+ 1.3.5
+
+
+ com.github.pagehelper
+ pagehelper
+ ${pagehelper.version}
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+ ch.qos.logback
+ logback-core
+ ${logback.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+
+
+
+ com.alibaba
+ fastjson
+ ${alibaba.fastjson}
+
+
+
+
+ io.springfox
+ springfox-swagger2
+ ${swagger.version}
+
+
+ io.swagger
+ swagger-models
+
+
+
+
+
+ io.swagger
+ swagger-models
+ ${swagger.model.version}
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${swagger.version}
+
+
+
+ com.github.xiaoymin
+ swagger-bootstrap-ui
+ ${swagger.bootstrap.ui.version}
+
+
+
+
+
+ springboot-demo
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
diff --git a/springboot-demo/src/main/java/com/pancm/Application.java b/springboot-demo/src/main/java/com/pancm/Application.java
new file mode 100644
index 0000000..413880d
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/Application.java
@@ -0,0 +1,40 @@
+package com.pancm;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+* @Title: Application
+* @Description: main
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @Date 2021/10/15
+**/
+@ServletComponentScan
+@SpringBootApplication
+@Slf4j
+public class Application {
+
+ public static void main(String[] args) throws UnknownHostException {
+ ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
+ Environment env = application.getEnvironment();
+ String ip = InetAddress.getLocalHost().getHostAddress();
+ String port = env.getProperty("server.port");
+ String path = env.getProperty("server.servlet.context-path");
+ log.info("\n----------------------------------------------------------\n\t" +
+ "Application springboot-demo is running! Access URLs:\n\t" +
+ "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
+ "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
+ "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
+ "----------------------------------------------------------");
+ }
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/config/CorsFilter.java b/springboot-demo/src/main/java/com/pancm/config/CorsFilter.java
new file mode 100644
index 0000000..05e8191
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/config/CorsFilter.java
@@ -0,0 +1,49 @@
+package com.pancm.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @Author pancm
+ * @Description
+ * @Date 2019/2/17
+ * @Param
+ * @return
+ **/
+@Configuration
+public class CorsFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) {
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
+ String origin = ((HttpServletRequest) servletRequest).getHeader("Origin");
+ if (StringUtils.isEmpty(origin)) {
+ origin = "*";
+ }
+ String rh = ((HttpServletRequest) servletRequest).getHeader("Access-Control-Request-Headers");
+ if (StringUtils.isEmpty(origin)) {
+ rh = "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control," +
+ "Content-Type,Authorization,SessionToken,Content-Disposition";
+ }
+ httpServletResponse.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+ httpServletResponse.setHeader("Access-Control-Allow-Origin", origin);
+ httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true");
+ httpServletResponse.setHeader("Access-Control-Allow-Headers", rh);
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
diff --git a/springboot-demo/src/main/java/com/pancm/config/PancmConfiguration.java b/springboot-demo/src/main/java/com/pancm/config/PancmConfiguration.java
new file mode 100644
index 0000000..9b7e58f
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/config/PancmConfiguration.java
@@ -0,0 +1,120 @@
+package com.pancm.config;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.github.pagehelper.PageHelper;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+import java.util.Objects;
+import java.util.Properties;
+
+import static com.pancm.config.PancmConfiguration.PACKAGE;
+
+/**
+ * @Author pancm
+ * @Description
+ * @Date 2019/2/17
+ * @Param
+ * @return
+ **/
+@Configuration
+@MapperScan(basePackages = {PACKAGE}, sqlSessionFactoryRef = "pancmSqlSessionFactory")
+public class PancmConfiguration {
+
+ static final String PACKAGE = "com.pancm.dao";
+ static final String MAPPER_LOCATION = "classpath:pancm/mapper/*.xml";
+ static final String CONFIG_LOCATION = "classpath:pancm/mybatis-config.xml";
+
+
+
+ @Value("${spring.datasource.pancm.driver-class-name}")
+ private String driverClassName;
+
+ @Value("${spring.datasource.pancm.url}")
+ private String url;
+
+ @Value("${spring.datasource.pancm.username}")
+ private String username;
+
+ @Value("${spring.datasource.pancm.password}")
+ private String password;
+
+
+ @Bean(name = "pancmDataSource")
+ @ConfigurationProperties(prefix = "spring.datasource.pancm")
+ @Primary
+ public DataSource pancmDataSource() {
+ DruidDataSource dataSource = new DruidDataSource();
+ dataSource.setDriverClassName(driverClassName);
+ dataSource.setUrl(url);
+ dataSource.setUsername(username);
+ dataSource.setPassword(password);
+ dataSource.setInitialSize(10);
+ dataSource.setMinIdle(10);
+ dataSource.setMaxActive(30);
+ dataSource.setMaxWait(30000);
+ dataSource.setRemoveAbandoned(true);
+ dataSource.setRemoveAbandonedTimeout(1800);
+ dataSource.setLogAbandoned(false);
+ dataSource.setTimeBetweenEvictionRunsMillis(60000);
+ dataSource.setMinEvictableIdleTimeMillis(300000);
+ dataSource.setValidationQuery("SELECT 1");
+ dataSource.setTestWhileIdle(true);
+ dataSource.setTestOnBorrow(false);
+ dataSource.setTestOnReturn(false);
+ dataSource.setPoolPreparedStatements(true);
+ dataSource.setMaxPoolPreparedStatementPerConnectionSize(500);
+ dataSource.setKeepAlive(true);
+ dataSource.setDbType("mysql");
+ return dataSource;
+ }
+
+ @Bean(name = "pancmSqlSessionFactory")
+ @Primary
+ public SqlSessionFactory pancmSqlSessionFactory(@Qualifier("pancmDataSource") DataSource dataSource) throws Exception {
+ SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
+ bean.setDataSource(dataSource);
+
+ //分页插件
+ PageHelper pageHelper = new PageHelper();
+ Properties properties = new Properties();
+ properties.setProperty("reasonable", "true");
+ properties.setProperty("supportMethodsArguments", "true");
+ properties.setProperty("returnPageInfo", "check");
+ properties.setProperty("params", "count=countSql");
+ pageHelper.setProperties(properties);
+
+ //添加插件
+ bean.setPlugins(new Interceptor[]{pageHelper});
+
+ bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
+ bean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(CONFIG_LOCATION));
+ Objects.requireNonNull(bean.getObject()).getConfiguration().setMapUnderscoreToCamelCase(true);
+ return bean.getObject();
+ }
+
+ @Bean(name = "pancmTransactionManager")
+ @Primary
+ public DataSourceTransactionManager testTransactionManager(@Qualifier("pancmDataSource") DataSource dataSource) {
+ return new DataSourceTransactionManager(dataSource);
+ }
+
+ @Bean(name = "pancmSqlSessionTemplate")
+ @Primary
+ public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("pancmSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
+ throws Exception {
+ return new SqlSessionTemplate(sqlSessionFactory);
+ }
+}
diff --git a/springboot-demo/src/main/java/com/pancm/config/SpringBeanFactory.java b/springboot-demo/src/main/java/com/pancm/config/SpringBeanFactory.java
new file mode 100644
index 0000000..9a6ed7a
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/config/SpringBeanFactory.java
@@ -0,0 +1,50 @@
+package com.pancm.config;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Title: SpringBeanFactory
+ * @Description:
+ * @Version:1.0.0
+ * @Since:jdk1.8
+ * @author pancm
+ * @Date 2021/7/2
+ **/
+@Component
+public class SpringBeanFactory implements ApplicationContextAware {
+
+ // Spring应用上下文环境
+ private static ApplicationContext applicationContext;
+
+ /**
+ * 实现ApplicationContextAware接口的回调方法,设置上下文环境
+ */
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ SpringBeanFactory.applicationContext = applicationContext;
+ }
+
+ public static ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ /**
+ * 获取对象 这里重写了bean方法,起主要作用
+ */
+ public static Object getBean(String beanId) throws BeansException {
+ if (applicationContext == null) return null;
+ return applicationContext.getBean(beanId);
+ }
+
+ /**
+ * 获取当前环境
+ */
+ public static String getActiveProfile() {
+ return applicationContext.getEnvironment().getActiveProfiles()[0];
+ }
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/config/SwaggerConfig.java b/springboot-demo/src/main/java/com/pancm/config/SwaggerConfig.java
new file mode 100644
index 0000000..1a93d99
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/config/SwaggerConfig.java
@@ -0,0 +1,64 @@
+package com.pancm.config;
+
+import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.RequestMethod;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Contact;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author pancm
+ * @Description
+ * @Date 2019/2/17
+ * @Param
+ * @return
+ **/
+@Configuration
+@EnableSwagger2
+@EnableSwaggerBootstrapUI
+public class SwaggerConfig {
+
+ @Bean
+ public Docket createRestApi() {
+ //添加head参数start
+ ParameterBuilder tokenPar = new ParameterBuilder();
+ List pars = new ArrayList();
+ tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
+ pars.add(tokenPar.build());
+ //添加head参数end
+
+
+ return new Docket(DocumentationType.SWAGGER_2)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("com.pancm.controller"))
+ .paths(PathSelectors.any())
+ .build()
+ .globalOperationParameters(pars)
+ ;
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("pancm-swagger2")
+ .description("Restful-API-Doc")
+ .termsOfServiceUrl("https://www.cnblogs.com/xuwujing")
+ .contact(new Contact("虚无境的博客", "https://www.cnblogs.com/xuwujing", "xxx@qq.com"))
+ .version("1.0")
+ .build();
+ }
+}
diff --git a/springboot-demo/src/main/java/com/pancm/controller/HomeController.java b/springboot-demo/src/main/java/com/pancm/controller/HomeController.java
new file mode 100644
index 0000000..527f9a6
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/controller/HomeController.java
@@ -0,0 +1,53 @@
+package com.pancm.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.pancm.util.FileHelper;
+import com.pancm.util.GetProperties;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+/**
+ * @Author pancm
+ * @Description
+ * @Date 2019/2/17
+ * @Param
+ * @return
+ **/
+@RestController
+@RequestMapping("/home")
+@Slf4j
+@Api(tags = "首页相关接口")
+public class HomeController {
+
+
+ @Value("${spring.profiles.active}")
+ String active;
+
+ private final static String VERSION_NAME = "version.txt";
+
+ @ApiOperation(value = "/version", notes = "版本信息")
+ @RequestMapping(value = "/version", method = {RequestMethod.GET})
+ public JSONObject version(HttpServletRequest request){
+ Map map = GetProperties.getAppSettings();
+ JSONObject result = new JSONObject();
+ result.put("git_branch", map.get("git_branch"));
+ result.put("build_time", map.get("build_time"));
+ result.put("git_commit", map.get("git_commit"));
+ result.put("app_name", map.get("build_app"));
+ result.put("profile", active);
+ result.put("version", FileHelper.readResourcesFile(VERSION_NAME));
+ return result;
+ }
+
+
+
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/controller/UserController.java b/springboot-demo/src/main/java/com/pancm/controller/UserController.java
new file mode 100644
index 0000000..94fa064
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/controller/UserController.java
@@ -0,0 +1,103 @@
+package com.pancm.controller;
+
+import com.pancm.vo.UserVO;
+import com.pancm.service.IUserService;
+import org.springframework.web.bind.annotation.*;
+
+
+import com.pancm.vo.ApiResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+
+/**
+* @Title: 用户表(User)表控制层
+* @Description:
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @date 2024-01-15 15:27:02
+*/
+@Api(tags = "用户表(User)")
+@RestController
+@RequestMapping("user")
+public class UserController {
+ /**
+ * 服务对象
+ */
+ @Autowired
+ private IUserService userService;
+
+
+ /**
+ * 新增一条数据
+ *
+ * @param userVO 实体类
+ * @return Response对象
+ */
+ @ApiOperation(value = "用户表新增",notes = "用户表新增")
+ @RequestMapping(value = "save", method = RequestMethod.POST)
+ public ApiResult insert(@RequestBody UserVO userVO, HttpServletRequest httpRequest) {
+ int result = userService.insert(userVO);
+ if (result > 0) {
+ return ApiResult.success();
+ }
+ return ApiResult.error("新增失败");
+ }
+
+ /**
+ * 修改一条数据
+ *
+ * @param userVO 实体类
+ * @return Response对象
+ */
+ @ApiOperation(value = "用户表修改",notes = "用户表修改")
+ @RequestMapping(value = "edit", method = RequestMethod.POST)
+ public ApiResult update(@RequestBody UserVO userVO, HttpServletRequest httpRequest) {
+ userService.update(userVO);
+ return ApiResult.success();
+ }
+
+ /**
+ * 删除一条数据
+ *
+ * @param userVO 参数对象
+ * @return Response对象
+ */
+ @ApiOperation(value = "用户表删除",notes = "用户表删除")
+ @RequestMapping(value = "del", method = RequestMethod.POST)
+ public ApiResult delete(@RequestBody UserVO userVO, HttpServletRequest httpRequest) {
+ userService.deleteById(userVO.getId());
+ return ApiResult.success();
+ }
+
+
+
+ /**
+ * 分页查询
+ *
+ */
+ @ApiOperation(value = "用户表查询",notes = "用户表查询")
+ @RequestMapping(value = "list", method = RequestMethod.POST)
+ public ApiResult list(@RequestBody UserVO userVO) {
+ return userService.list(userVO);
+ }
+
+ /**
+ * 详情查询
+ *
+ */
+ @ApiOperation(value = "用户表详情",notes = "用户表详情")
+ @RequestMapping(value = "view", method = RequestMethod.GET)
+ public ApiResult view( @RequestParam("id") Long id) {
+ return ApiResult.success(userService.queryById(id));
+ }
+}
diff --git a/springboot-demo/src/main/java/com/pancm/dao/UserDao.java b/springboot-demo/src/main/java/com/pancm/dao/UserDao.java
new file mode 100644
index 0000000..bce150e
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/dao/UserDao.java
@@ -0,0 +1,86 @@
+package com.pancm.dao;
+
+import com.pancm.model.User;
+import com.pancm.vo.UserVO;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Mapper;
+import java.util.List;
+
+ /**
+* @Title: 用户表(User)表数据库访问层
+* @Description:
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @date 2024-01-15 15:27:04
+*/
+@Mapper
+public interface UserDao {
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param id 主键
+ * @return 实例对象
+ */
+ UserVO queryById(Long id);
+
+
+ /**
+ * 通过实体查询一条数据
+ *
+ * @param userVO 实例对象
+ * @return 对象列表
+ */
+ UserVO findOne(UserVO userVO);
+
+ /**
+ * 通过实体作为筛选条件查询
+ *
+ * @param userVO 实例对象
+ * @return 对象列表
+ */
+ List queryAll(UserVO userVO);
+
+ /**
+ * 新增数据
+ *
+ * @param user 实例对象
+ * @return 影响行数
+ */
+ int insert(User user);
+
+ /**
+ * 批量新增数据(MyBatis原生foreach方法)
+ *
+ * @param entities List 实例对象列表
+ * @return 影响行数
+ */
+ int insertBatch(@Param("entities") List entities);
+
+ /**
+ * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+ *
+ * @param entities List 实例对象列表
+ * @return 影响行数
+ */
+ int insertOrUpdateBatch(@Param("entities") List entities);
+
+ /**
+ * 修改数据
+ *
+ * @param user 实例对象
+ * @return 影响行数
+ */
+ int update(User user);
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param id 主键
+ * @return 影响行数
+ */
+ int deleteById(Long id);
+
+}
+
diff --git a/springboot-demo/src/main/java/com/pancm/model/User.java b/springboot-demo/src/main/java/com/pancm/model/User.java
new file mode 100644
index 0000000..d440a6c
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/model/User.java
@@ -0,0 +1,71 @@
+package com.pancm.model;
+
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+
+import javax.persistence.Column;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.sql.Date;
+
+ /**
+* @Title: 用户表(User)实体类
+* @Description:
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @date 2024-01-15 15:27:05
+*/
+@Data
+@Table(name = "user")
+public class User implements Serializable {
+ private static final long serialVersionUID = -59671741667391987L;
+ /**
+ * ID
+ */
+ @Column(name = "id")
+ private Long id;
+ /**
+ * 姓名
+ */
+ @Column(name = "name")
+ private String name;
+ /**
+ * 性别
+ */
+ @Column(name = "sex")
+ private Integer sex;
+ /**
+ * 年龄
+ */
+ @Column(name = "age")
+ private Integer age;
+ /**
+ * 创建时间
+ */
+ @Column(name = "create_time")
+ private Date createTime;
+ /**
+ * 创建人
+ */
+ @Column(name = "create_by")
+ private String createBy;
+ /**
+ * 更新时间
+ */
+ @Column(name = "update_time")
+ private Date updateTime;
+ /**
+ * 更新人
+ */
+ @Column(name = "update_by")
+ private String updateBy;
+
+
+ @Override
+ public String toString(){
+ return JSONObject.toJSONString(this);
+ }
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/service/IUserService.java b/springboot-demo/src/main/java/com/pancm/service/IUserService.java
new file mode 100644
index 0000000..f87a804
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/service/IUserService.java
@@ -0,0 +1,60 @@
+package com.pancm.service;
+
+import com.pancm.vo.UserVO;
+import com.pancm.vo.ApiResult;
+import java.util.List;
+
+
+ /**
+* @Title: 用户表(User)表服务接口
+* @Description:
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @date 2024-01-15 15:27:03
+*/
+public interface IUserService {
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param id 主键
+ * @return 实例对象
+ */
+ UserVO queryById(Long id);
+
+
+ /**
+ * 通过实体作为筛选条件查询
+ *
+ * @param userVO 实例对象
+ * @return 对象列表
+ */
+ ApiResult list(UserVO userVO);
+
+
+ /**
+ * 新增数据
+ *
+ * @param userVO 实例对象
+ * @return 实例对象
+ */
+ int insert(UserVO userVO);
+
+ /**
+ * 修改数据
+ *
+ * @param userVO 实例对象
+ * @return 实例对象
+ */
+ int update(UserVO userVO);
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param id 主键
+ * @return 是否成功
+ */
+ boolean deleteById(Long id);
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/service/impl/UserServiceImpl.java b/springboot-demo/src/main/java/com/pancm/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..a7a5268
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/service/impl/UserServiceImpl.java
@@ -0,0 +1,96 @@
+package com.pancm.service.impl;
+
+
+import com.pancm.vo.UserVO;
+import com.pancm.model.User;
+import com.pancm.dao.UserDao;
+import com.pancm.service.IUserService;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.pancm.vo.ApiResult;
+import com.pancm.vo.PageResult;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.BeanUtils;
+import javax.annotation.Resource;
+import java.util.List;
+
+
+
+/**
+* @Title: 用户表(User)表服务实现类
+* @Description:
+* @Version:1.0.0
+* @Since:jdk1.8
+* @author pancm
+* @date 2024-01-15 15:27:04
+*/
+@Service("userService")
+public class UserServiceImpl implements IUserService {
+ @Resource
+ private UserDao userDao;
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param id 主键
+ * @return 实例对象
+ */
+ @Override
+ public UserVO queryById(Long id) {
+ return this.userDao.queryById(id);
+ }
+
+
+ /**
+ * 根据条件查询
+ *
+ * @return 实例对象的集合
+ */
+ @Override
+ public ApiResult list(UserVO user) {
+ int pageNum = user.getPageNum();
+ int pageSize = user.getPageSize();
+ Page page = PageHelper.startPage(pageNum, pageSize);
+ List result = userDao.queryAll(user);
+ return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum));
+
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param userVO 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int insert(UserVO userVO) {
+ User user = new User();
+ BeanUtils.copyProperties(userVO,user);
+ return userDao.insert(user);
+ }
+
+ /**
+ * 修改数据
+ *
+ * @param userVO 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int update(UserVO userVO) {
+ User user = new User();
+ BeanUtils.copyProperties(userVO,user);
+ return userDao.update(user);
+ }
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param id 主键
+ * @return 是否成功
+ */
+ @Override
+ public boolean deleteById(Long id) {
+ return this.userDao.deleteById(id) > 0;
+ }
+}
diff --git a/springboot-demo/src/main/java/com/pancm/util/FileHelper.java b/springboot-demo/src/main/java/com/pancm/util/FileHelper.java
new file mode 100644
index 0000000..b5fa52c
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/util/FileHelper.java
@@ -0,0 +1,321 @@
+package com.pancm.util;
+
+import com.alibaba.fastjson.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+
+
+/**
+ * @Author pancm
+ * @Description
+ * @Date 2019/2/17
+ * @Param
+ * @return
+ **/
+public class FileHelper {
+
+ private final static Logger log = LoggerFactory.getLogger(FileHelper.class);
+
+ /**
+ * 行为单位读取文件,常用于读面向行的格式化文件
+ *
+ * @param folder 文件目录
+ * @param fileName 文件名
+ * @return 文件内容,字符串格式
+ */
+ public static String readFileToString(String folder, String fileName) {
+ return readFileToString(folder + "/" + fileName);
+ }
+
+ /**
+ * 以行为单位读取文件,常用于读面向行的格式化文件
+ *
+ * @param filePath 文件路径
+ * @return 文件内容,字符串
+ */
+ public static String readFileToString(String filePath) {
+ File file = new File(filePath);
+ BufferedReader reader = null;
+ StringBuilder builder = new StringBuilder();
+ try {
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
+ String tempString = null;
+ int line = 1;
+ // 一次读入一行,直到读入null为文件结束
+ while ((tempString = reader.readLine()) != null) {
+ // 显示行号
+ builder.append(tempString);
+ }
+ reader.close();
+ } catch (IOException e) {
+ throw new RuntimeException("file error#" + filePath, e);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+ return builder.toString();
+ }
+
+ /**
+ * 读取文件,处理成 JSON格式
+ *
+ * @param filePath 文件绝对路径
+ * @return json格式
+ */
+ public static Object readFileToJson(String filePath) {
+ String content = FileHelper.readFileToString(filePath);
+ return JSONObject.parse(content);
+ }
+
+ /**
+ * 相对路径转换为绝对路径
+ *
+ * @param folderInput 相对路径,如./
+ * @return 文件目录的绝对路径
+ */
+ public static String convertFolder(String folderInput) {
+ String folder = folderInput;
+ if (folderInput.startsWith("./")) {
+ String relativeFolder = folderInput.replace("./", "");
+ String dir = System.getProperty("user.dir");
+ folder = dir + "/" + relativeFolder;
+ }
+ return folder;
+ }
+
+
+ /**
+ * @return boolean
+ * @Author pancm
+ * @Description 创建文件夹--多层
+ * @Date 2021/2/24
+ * @Param [dir]
+ **/
+ public static boolean createMultilayerFile(String dir) {
+ try {
+ File dirPath = new File(dir);
+ if (!dirPath.exists()) {
+ dirPath.mkdirs();
+ }
+ } catch (Exception e) {
+ log.error("创建多层目录操作出错: " + e.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * 文件本地存储
+ *
+ * @param file 上传文件格式
+ * @param destFolder 目标目录
+ * @param destFileName 目标文件名
+ * @return
+ */
+ public static boolean saveFile(MultipartFile file, String destFolder, String destFileName) {
+ File dest = new File(destFolder + "/" + destFileName);
+// if(!dest.getParentFile().exists()){
+// dest.getParentFile().mkdir();
+// }
+ createMultilayerFile(destFolder);
+ try {
+ file.transferTo(dest);
+ return true;
+ } catch (Exception e) {
+ log.error("file save error", e);
+ }
+ return false;
+ }
+
+
+ public static boolean saveFile(byte[] buf, String filePath, String fileName) {
+ BufferedOutputStream bos = null;
+ FileOutputStream fos = null;
+ File file = null;
+ try {
+ createMultilayerFile(filePath);
+ file = new File(filePath + File.separator + fileName);
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream(fos);
+ bos.write(buf);
+ } catch (Exception e) {
+ log.error("file save error", e);
+ return false;
+ } finally {
+ if (bos != null) {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * 文件大小,单位 MB
+ *
+ * @param size 文件大小,单位byte
+ * @return 文件大小,MB
+ */
+ public static long getSizeInMb(long size) {
+ return size / 1024 / 1024;
+ }
+
+ /**
+ * 文件大小,单位 GB
+ *
+ * @param size 文件大小,单位byte
+ * @return 文件大小,GB
+ */
+ public static long getSizeInGb(long size) {
+ return size / 1024 / 1024 / 1024;
+ }
+
+ /**
+ * 获得文件扩展名
+ *
+ * @param fileName 文件名
+ * @return 扩展名,dot 后面的,如xls
+ */
+ public static String getFileExtension(String fileName) {
+ if (fileName == null) {
+ return null;
+ }
+ int index = fileName.lastIndexOf(".");
+ if (index == -1) {
+ return null;
+ }
+ return fileName.substring(index + 1);
+ }
+
+ /**
+ * 删除文件
+ *
+ * @param folder 目录
+ * @param fileName 文件名
+ * @return 删除是否成功
+ */
+ public static boolean deleteFile(String folder, String fileName) {
+ return deleteFile(folder + "/" + fileName);
+ }
+
+ /**
+ * 删除文件
+ *
+ * @param filePath 文件的绝对路径
+ * @return 删除是否成功
+ */
+ public static boolean deleteFile(String filePath) {
+ if (filePath == null) {
+ return false;
+ }
+ try {
+ File f = new File(filePath);
+ if (f.exists()) {
+ return f.delete();
+ }
+ } catch (Exception ex) {
+ log.error("delete file error#" + filePath, ex);
+ }
+ return false;
+ }
+
+
+ public static String readResourcesFile(String path) {
+ StringBuilder sb = new StringBuilder();
+ try (InputStream in = FileHelper.class.getClassLoader().getResourceAsStream(path)) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String msg = null;
+ while ((msg = reader.readLine()) != null) {
+ sb.append(msg);
+// .append("\n")
+ }
+
+ } catch (IOException e) {
+ log.error("read file error#", e);
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * @Author beixing
+ * @Description 文件夹复制
+ * @Date 2021/4/27
+ * @Param
+ * @return
+ **/
+ public static void copyFolder(String src, String des) {
+ //初始化文件复制
+ File file1 = new File(src);
+ //把文件里面内容放进数组
+ File[] fs = file1.listFiles();
+ //初始化文件粘贴
+ File file2 = new File(des);
+ //判断是否有这个文件有不管没有创建
+ if (!file2.exists()) {
+ file2.mkdirs();
+ }
+ //遍历文件及文件夹
+ for (File f : fs) {
+ if (f.isFile()) {
+ ///调用文件拷贝的方法
+ fileCopy(f.getPath(), des + File.separator + f.getName());
+ } else if (f.isDirectory()) {
+ //文件夹
+ copyFolder(f.getPath(), des + File.separator + f.getName());
+ }
+ }
+
+ }
+
+ /**
+ * 文件复制的具体方法
+ */
+ public static void fileCopy(String src, String des) {
+ //io流固定格式
+ try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(des))) {
+ int i = -1;//记录获取长度
+ byte[] bt = new byte[2014];//缓冲区
+ while ((i = bis.read(bt)) != -1) {
+ bos.write(bt, 0, i);
+ }
+ } catch (IOException e) {
+ log.error("read file error#", e);
+ }
+ }
+
+
+ public static void main(String[] args) {
+ String source = "D:\\video\\ceshi\\2021\\4\\26\\18\\34020000001310000001";
+ String target = "D:\\video\\diagnosis\\2021\\4\\26\\18\\34020000001310000001";
+// copyFolder(source,target);
+
+ String srcFile = "D:\\video\\ceshi\\2021\\5\\7\\10\\34020000001310000001\\34020000001310000001_20210507105454_00001.jpg";
+ String desFile = "D:\\video\\34020000001310000001_20210507105454_测试.jpg";
+ fileCopy(srcFile,desFile);
+
+ }
+
+
+}
diff --git a/springboot-demo/src/main/java/com/pancm/util/GetProperties.java b/springboot-demo/src/main/java/com/pancm/util/GetProperties.java
new file mode 100644
index 0000000..7c580e8
--- /dev/null
+++ b/springboot-demo/src/main/java/com/pancm/util/GetProperties.java
@@ -0,0 +1,94 @@
+package com.pancm.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.Map.Entry;
+
+/**
+ * Title: getProperties
+ * Description: 获取配置文件
+ * Version:1.0.0
+ *
+ * @author pancm
+ * @date 2018年1月4日
+ */
+public class GetProperties {
+ private static Map appSettings = new HashMap();
+ private static final Logger LOG = LoggerFactory.getLogger(GetProperties.class);
+ private String pathName="build.properties";
+ /**
+ * 初始化系统默认参数
+ */
+ private GetProperties(){
+ init();
+ }
+
+ private void init(){
+ InputStream in = null;
+ try{
+ //获取resource中的配置
+ in=this.getClass().getClassLoader().getResourceAsStream(pathName);
+ //获取项目同级的配置
+// in=new FileInputStream(new File(pathName));
+ Properties prop = new Properties();
+ prop.load(in);
+ Set> buf = prop.entrySet();
+ Iterator> it = buf.iterator();
+ while(it.hasNext()){
+ Entry