介绍

对Spring Boot项目进行相关统合的支持

项目导航

引入

确保当前仓库有该包,暂未录入公共仓库,自行放入。

  1. <dependency>
  2. <groupId>com.xyz</groupId>
  3. <artifactId>xyz-support</artifactId>
  4. <version>1.0.0</version>
  5. </dependency>

当前引用Spring Boot版本

2.1.3.RELEASE

当前引用外部依赖的版本

  • 谷歌guava:28.0-jre
  • 谷歌gson:2.8.5
  • 七牛云sdk:7.7.0
  • okhttp:3.14.2
  • commons-net:3.4
  • commons-io:2.11.0
  • poi:3.9

提示:maven仓库方式引用的话,上述外部依赖的版本若与本地不一致,以自身情况考量并存还是存其一; 若以普通jar本地引入,请注意引入上述依赖。或可对源码进行修改后运行无误后进行打包使用。

当前已支持的服务

文件(对象存储)服务

  • 本地存储已支持
  • Ftp存储已支持
  • 七牛云存储已支持

文档服务

  • excel服务
    • 使用poi(支持xls和xlsx操作)

手册

文件(对象存储)服务

配置

注意:目前只支持Spring Boot的配置方式,即application.properties(application.yml), 讲解将以application.properties进行(application.yml同理)。

  1. # 文件服务的启动标志 true/false
  2. xyz.support.file.enable=true
  3. # local文件服务配置 list形式 严格从0下标递增,否则不识别,application.yml中直接-替代(推荐)
  4. xyz.support.file.local...
  5. # 举例local
  6. # local服务名 必传(没有服务名配啥呢)
  7. xyz.support.file.local[0].serviceName=xxx
  8. # local指定的根路径 必传
  9. xyz.support.file.local[0].localPath=xxx
  10. # ftp文件服务配置 list形式 严格从0下标递增,否则不识别,application.yml中直接-替代(推荐)
  11. xyz.support.file.ftp...
  12. # 举例ftp
  13. # ftp服务名 必传
  14. xyz.support.file.ftp[0].serviceName=xxx
  15. # ftp指定的host 不传默认为127.0.0.1
  16. xyz.support.file.ftp[0].host=127.0.0.1
  17. # ftp指定的port 不传默认为21
  18. xyz.support.file.ftp[0].port=21
  19. # ftp指定的timeout 不传默认为5000
  20. xyz.support.file.ftp[0].timeout=5000
  21. # ftp指定的username 必传
  22. xyz.support.file.ftp[0].username=xxx
  23. # ftp指定的password 必传
  24. xyz.support.file.ftp[0].password=xxx
  25. # 七牛云文件服务配置 list形式 严格从0下标递增,否则不识别,application.yml中直接-替代(推荐)
  26. xyz.support.file.qiniu...
  27. # 举例七牛云
  28. # 七牛云服务名 必传
  29. xyz.support.file.qiniu[0].serviceName=xxx
  30. # 七牛云accessKey 必传
  31. xyz.support.file.qiniu[0].accessKey=xxx
  32. # 七牛云secretKey 必传
  33. xyz.support.file.qiniu[0].secretKey=xxx
  34. # 七牛云bucket(空间名) 必传
  35. xyz.support.file.qiniu[0].bucket=xxx
  36. # 七牛云domain(访问域名) 必传
  37. xyz.support.file.qiniu[0].domain=xxx
  38. # 七牛云publicFlag(空间公开标志 true/false) 默认为false
  39. xyz.support.file.qiniu[0].publicFlag=false

使用例子

假定进行了如下配置,以application.yml形式:

  1. xyz:
  2. support:
  3. file:
  4. enable: true
  5. local:
  6. - serviceName: localFileService
  7. localPath: /localFile

若要对服务进行调用,业务服务中(按正常注入bean的方式即可):

  1. @Resource
  2. private FileInterface localFileService;

api介绍

更详细的解释见**FileInterface**

method description
String upload(File file) File的方式上传,文件名取本名,文件路径在当前服务根路径
String upload(File file, String fileName) File的方式上传,文件名取自定义,文件路径在当前服务根路径
String upload(File file, String fileName, String filePath) File的方式上传,文件名取自定义,文件路径也取自定义(相对于当前服务根路径)
String upload(MultipartFile file) MultipartFile的方式上传,文件名取本名,文件路径在当前服务根路径
String upload(MultipartFile file, String fileName) MultipartFile的方式上传,文件名取自定义,文件路径在当前服务根路径
String upload(MultipartFile file, String fileName, String filePath) MultipartFile的方式上传,文件名取自定义,文件路径也取自定义(相对于当前服务根路径)
String upload(InputStream is, String fileName) 流的方式上传,文件名取自定义,文件路径在当前服务根路径
String upload(InputStream is, String fileName, String filePath) 流的方式上传,文件名取自定义,文件路径也取自定义(相对于当前服务根路径)
File download(String fileName, String filePath) 文件下载,提供File
byte[] download(String fileName) 文件下载,提供字节数组

文档服务

excel服务

提供的服务包含解析excel成对象导出对象成excel,支持常规性的excel内容识别(标准的一行行数据,不要出现隐藏行,使用时请注意),支持常规类型数据的导出(包括Date,专属注解支持)。

配置

注意:目前只支持Spring Boot的配置方式,即application.properties(application.yml), 讲解将以application.properties进行(application.yml同理)。

  1. # excel服务的启动标志 true/false
  2. xyz.support.document.excel.enable=true
  3. # excel服务bean配置 list形式 严格从0下标递增,否则不识别,application.yml中直接-替代(推荐)
  4. xyz.support.document.excel.bean...
  5. # 服务名 必传
  6. xyz.support.document.excel.bean[0].serviceName=xxx
  7. # 服务的类型 poi、custom 除了custom自定义,其他类型将选用默认的对应实现 不传默认为poi,但不能传错
  8. xyz.support.document.excel.bean[0].type=poi
  9. # 自定义服务的全限定类名 type选custom时需指定(若无法加载,将会报错)
  10. xyz.support.document.excel.bean[0].clazz=xxx

使用例子

假定进行了如下配置,以application.yml形式:

  1. xyz:
  2. support:
  3. document:
  4. excel:
  5. enable: true
  6. bean:
  7. - serviceName: excelService
  8. type: custom
  9. clazz: com.xyz.support.document.excel.poi.DefaultPoiExcelOperation

若要对服务进行调用,业务服务中(按正常注入bean的方式即可):

  1. @Resource
  2. private ExcelOperation excelService;

api介绍

更详细的解释见**ExcelOperation**

method description
List parse(File file, Class resultType) 解析excel到对应bean,忽略第一行数据(认为是头)
List parse(File file, boolean filterFirstRow, Class resultType) 解析excel到对应bean,忽不忽略第一行由调用方决定
List parse(MultiFile file, Class resultType) 解析excel(MultipartFile)到对应bean,忽略第一行数据(认为是头)
List parse(MultiFile file, boolean filterFirstRow, Class resultType) 解析excel(MultipartFile)到对应bean,忽不忽略第一行由调用方决定
void export(File target, Class dataType, List dataList) 导出数据生成excel,数据按bean并由对应规则解析出来,导出到本地文件
void export(HttpServletResponse response, String fileName, Class dataType, List dataList) 导出数据生成excel,数据按bean并由对应规则解析出来,通过网络导出
void export(File target, SheetItem sheetItem) 导出数据生成excel,数据通过通用赋值对象传递,导出到本地文件
void export(HttpServletResponse response, String fileName, SheetItem sheetItem) 导出数据生成excel,数据通过通用赋值对象传递,通过网络导出