From 3df871b59c903b5e1d7e416b8353c435943c0841 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Tue, 8 Sep 2020 22:55:48 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A1=88=E4=BE=8B?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8932a7..ba2e06e 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,6 @@ ``` ## 示例 ```java -1. 项目案例:http://106.12.122.216:8080/ssm/cms/ +1. 项目案例:www.000oo1.com/ssm/cms/ 2. 默认账号/密码:admin/123 ``` \ No newline at end of file From dbc95a4f8cb32f78954c4b777c731c20eeb1ef41 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Wed, 9 Sep 2020 07:23:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4minio=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 + .../com/lq/cms/web/sys/UserController.java | 7 +- src/main/java/com/lq/code/util/MinUtil.java | 148 ++++++++++++++++++ src/main/profile/dev/file.properties | 7 +- src/main/profile/dev/jdbc.properties | 2 +- src/main/profile/dev/redis.properties | 4 +- src/main/resources/spring-mybatis-config.xml | 3 + 7 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/lq/code/util/MinUtil.java diff --git a/pom.xml b/pom.xml index 9a7936b..0c0da45 100644 --- a/pom.xml +++ b/pom.xml @@ -547,6 +547,13 @@ compile + + + io.minio + minio + 7.1.2 + + diff --git a/src/main/java/com/lq/cms/web/sys/UserController.java b/src/main/java/com/lq/cms/web/sys/UserController.java index eca0748..7d9bf67 100755 --- a/src/main/java/com/lq/cms/web/sys/UserController.java +++ b/src/main/java/com/lq/cms/web/sys/UserController.java @@ -55,6 +55,9 @@ public class UserController { @Autowired private SysUserRoleService sysUserRoleService; + @Autowired + private MinUtil minUtil; + @Value("${file.upload}") private String fileLoadPath; @@ -108,7 +111,9 @@ public class UserController { @RequiresPermissions(INDEX_URL+ Constant.PERSSION_MARK+Constant.PERMISSION_UPDATE) @ResponseBody @RequestMapping("/update") - public Object update(SysUserVo vo,@RequestParam(value = "file",required = false) MultipartFile file){ + public Object update(SysUserVo vo,@RequestParam(value = "file",required = false) MultipartFile file) throws IOException { + System.out.println(minUtil); + minUtil.uploadFile(file.getInputStream()); Date nowTime = new Date(); AjaxResult ajaxResult = new AjaxResult(); if (vo!=null&&vo.getId()!=null){ diff --git a/src/main/java/com/lq/code/util/MinUtil.java b/src/main/java/com/lq/code/util/MinUtil.java new file mode 100644 index 0000000..4a77e37 --- /dev/null +++ b/src/main/java/com/lq/code/util/MinUtil.java @@ -0,0 +1,148 @@ +package com.lq.code.util; + +import io.minio.BucketExistsArgs; +import io.minio.MakeBucketArgs; +import io.minio.MinioClient; +import io.minio.PutObjectArgs; +import io.minio.errors.*; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +/** + * minio 客户端 + * @author qi + */ +@Component +public class MinUtil { + + /** + * minio服务地址 + */ + @Value("minio.server.url") + private String serverUrl; + + /** + * 存储桶名称 + */ + @Value("minio.bucket.name") + private String bucketName; + + /** + * minio账号 + */ + @Value("minio.accesskey") + private String accessKey; + + /** + * minio密码 + */ + @Value("minio.secretkey") + private String secretKey; + + /** + * 上传图片 + * @param inputStream + * @return + */ + public String uploadFile(InputStream inputStream){ + String fileName = "timg.jpeg"; + //初始化客户端 + MinioClient minioClient = MinioClient.builder() + .endpoint(serverUrl) + .credentials(accessKey,secretKey) + .build(); + + try { + int size = inputStream.available(); + BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(bucketName).build(); + //判断桶是否存在 + boolean isExist = minioClient.bucketExists(bucketExistsArgs); + if (!isExist){ + minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); + } + PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket(bucketName).object(fileName).stream(inputStream,size,-1).build(); + minioClient.putObject(putObjectArgs); + } catch (ErrorResponseException e) { + e.printStackTrace(); + } catch (InsufficientDataException e) { + e.printStackTrace(); + } catch (InternalException e) { + e.printStackTrace(); + } catch (InvalidBucketNameException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } catch (InvalidResponseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (ServerException e) { + e.printStackTrace(); + } catch (XmlParserException e) { + e.printStackTrace(); + } catch (RegionConflictException e) { + e.printStackTrace(); + } + return fileName; + } + + public static void main(String[] args) { + String fileName = "timg.jpeg"; + //初始化客户端 + MinioClient minioClient = MinioClient.builder() + .endpoint("http://192.168.31.19:9000") + .credentials("minioadmin","minioadmin") + .build(); + + try { + File file = new File("/Users/liangqi/Downloads/timg.jpeg"); + InputStream inputStream = new FileInputStream(file); + if (file.exists()){ + System.out.println("========文件存在======="); + } + + BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket("ssm").build(); + //判断桶是否存在 + boolean isExist = minioClient.bucketExists(bucketExistsArgs); + if (!isExist){ + minioClient.makeBucket(MakeBucketArgs.builder().bucket("ssm").build()); + } + + PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket("ssm").object(fileName).stream(inputStream,inputStream.available(),-1).build(); + minioClient.putObject(putObjectArgs); + } catch (ErrorResponseException e) { + e.printStackTrace(); + } catch (InsufficientDataException e) { + e.printStackTrace(); + } catch (InternalException e) { + e.printStackTrace(); + } catch (InvalidBucketNameException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } catch (InvalidResponseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (ServerException e) { + e.printStackTrace(); + } catch (XmlParserException e) { + e.printStackTrace(); + } catch (RegionConflictException e) { + e.printStackTrace(); + } + System.out.println("===============文件上传成功!!"); + } +} diff --git a/src/main/profile/dev/file.properties b/src/main/profile/dev/file.properties index 70c8c53..6b4fd68 100644 --- a/src/main/profile/dev/file.properties +++ b/src/main/profile/dev/file.properties @@ -1 +1,6 @@ -file.upload=/Users/qi/java/fileManger/ \ No newline at end of file +file.upload=/Users/liangqi/java/fileManger + +minio.server.url= +minio.bucket.name= +minio.accesskey= +minio.secretkey= \ No newline at end of file diff --git a/src/main/profile/dev/jdbc.properties b/src/main/profile/dev/jdbc.properties index 7b3df51..c0b614d 100644 --- a/src/main/profile/dev/jdbc.properties +++ b/src/main/profile/dev/jdbc.properties @@ -2,7 +2,7 @@ jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://192.168.31.111:3306/ssm?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8 jdbc.user=root -jdbc.password=mysql +jdbc.password=liangqi@mysql #--------数据库连接池配置 ------- durid.pool.initialSize=5 durid.pool.maxActive=5 diff --git a/src/main/profile/dev/redis.properties b/src/main/profile/dev/redis.properties index 59971fb..7616aac 100644 --- a/src/main/profile/dev/redis.properties +++ b/src/main/profile/dev/redis.properties @@ -1,6 +1,6 @@ -redis.host=192.168.31.110 +redis.host=192.168.31.111 redis.port=6379 -redis.pass= +redis.pass=liangqi@redis redis.timeout=-1 redis.maxTotal=15 diff --git a/src/main/resources/spring-mybatis-config.xml b/src/main/resources/spring-mybatis-config.xml index dfc6e85..aca41f3 100644 --- a/src/main/resources/spring-mybatis-config.xml +++ b/src/main/resources/spring-mybatis-config.xml @@ -14,6 +14,9 @@ + + + From 4d286af61a3ad4fd046ec8cd30e1840bd224b47f Mon Sep 17 00:00:00 2001 From: qi_liang Date: Sat, 12 Sep 2020 12:11:56 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4oss=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lq/cms/web/sys/OssController.java | 4 ++++ src/main/java/com/lq/cms/web/sys/UserController.java | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/lq/cms/web/sys/OssController.java diff --git a/src/main/java/com/lq/cms/web/sys/OssController.java b/src/main/java/com/lq/cms/web/sys/OssController.java new file mode 100644 index 0000000..a42f1e4 --- /dev/null +++ b/src/main/java/com/lq/cms/web/sys/OssController.java @@ -0,0 +1,4 @@ +package com.lq.cms.web.sys; + +public class OssController { +} diff --git a/src/main/java/com/lq/cms/web/sys/UserController.java b/src/main/java/com/lq/cms/web/sys/UserController.java index 7d9bf67..6232093 100755 --- a/src/main/java/com/lq/cms/web/sys/UserController.java +++ b/src/main/java/com/lq/cms/web/sys/UserController.java @@ -112,14 +112,18 @@ public class UserController { @ResponseBody @RequestMapping("/update") public Object update(SysUserVo vo,@RequestParam(value = "file",required = false) MultipartFile file) throws IOException { - System.out.println(minUtil); - minUtil.uploadFile(file.getInputStream()); + Date nowTime = new Date(); AjaxResult ajaxResult = new AjaxResult(); if (vo!=null&&vo.getId()!=null){ SysUser sysUser = sysUserService.findOne(vo.getId()); BeanUtil.copyNotNull(sysUser,vo); sysUser.setUpdateTime(nowTime); + UUID uuid = UUID.randomUUID(); + String fileType = FileUtil.fileFormat(file.getOriginalFilename()); + String newFileName = "wechat/"+uuid.toString()+"."+fileType; + + minUtil.uploadFile(newFileName,file.getInputStream()); String uploadFileName =upLoadFile(file); sysUser.setImgUrl(uploadFileName); sysUserService.update(sysUser); From dd495f9ca6f8b98cd599926322f5338804d03fbc Mon Sep 17 00:00:00 2001 From: qi_liang Date: Mon, 14 Sep 2020 00:44:16 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 98 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ba2e06e..ab8f52f 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,72 @@ # ssm项目 ## ssm 介绍 -```java -一个基于spring mvc+mybatis的框架。页面是采用aceAdmin+easyUI. -使用shiro作为安全框架,做权限控制 -``` + +***一个基于spring mvc+mybatis的框架。页面是采用aceAdmin+easyUI. +使用shiro作为安全框架,做权限控制*** + ## ssm开发环境 -```java -1. jdk 1.8 -2. maven 3 -3. mysql 5.6 -4. redis -5. tomcat 8 -``` + +* jdk1.8 +* Maven 3 +* Mysql 5.6 +* tomcat 8 +* Redis + +## 技术栈 + +| 技术 | git地址 | 说明 | +| -------------- | ------------------------------------------------- | :-------------------------------- | +| Spring | | | +| spring mvc | | | +| Apache Shiro | | 安全框架 | +| Mybatis-plus | https://gitee.com/baomidou/mybatis-plus | 数据持久层框架 | +| spring session | https://github.com/spring-projects/spring-session | 在集群环境下,解决session同步问题 | +| Minio | https://github.com/minio/minio-java | 文件服务系统 | +| hutool | https://gitee.com/loolly/hutool | 国产工具类 | +| jmockdata | https://github.com/jsonzou/jmockdata | 测试工具类 | +| Durid | https://github.com/alibaba/druid | 数据库连接池 | +| zxing | https://github.com/zxing/zxing | 二维码生成工具类 | +| jsoup | | 爬虫工具 | + + + + + + + + + + + ## ssm 使用说明 -```java -1. 菜单目录采用设计模式中的容器模式,理论上是可以实现三级甚至四级的菜单目录(参考代码:com.lq.cms.mode.MenusComposite). -2. 自定义一个mybatis的xml生成插件(CreateMapperFileUtil),配合BaseDao一起使用.基本实现单表的CURD操作功能 -3. 自定义实体同步数据库表结构插件(com.lq.code.executor.processor.InstantiationTracingBeanPostProcessor) -4. AdminBaseDao,AdminBaseServer,AdminBaseController.三层类结构的继承。可以实现简单模块基本管理功能。 -5. 使用spring session整合redis实现在集群中session共享的效果 -6. 微信公众号相关开发代码(com.lq.wechat),其中客服消息采用了建造者模式(com.lq.wechat.mode.template)。 -``` -## 三层架构理念: -```java -1. 数据库表与mapping.xml一一对应。 -2. dao层代码密度低,dao层代码尽量通用,以工具类形式使用。便于代码重用 -3. service层代码密度高 通过组合复用原则使用dao层工具类,实现业务逻辑 -4. controller层代码密度低 只负责简单的数据接受和转发。以及页面跳转的控制 - -``` + ++ 菜单目录采用设计模式中的容器模式,理论上是可以实现三级甚至四级的菜单目录(参考代码:com.lq.cms.mode.MenusComposite). + ++ 自定义一个mybatis的xml生成插件(CreateMapperFileUtil),配合BaseDao一起使用.基本实现单表的CURD操作功能 + ++ 自定义实体同步数据库表结构插件(com.lq.code.executor.processor.InstantiationTracingBeanPostProcessor) + ++ AdminBaseDao,AdminBaseServer,AdminBaseController.三层类结构的继承。可以实现简单模块基本管理功能。 + ++ 使用spring session整合redis实现在集群中session共享的效果 + ++ 微信公众号相关开发代码(com.lq.wechat),其中客服消息采用了建造者模式(com.lq.wechat.mode.template)。 + + + +## 三层架构理念 + +- 数据库表与mapping.xml一一对应。 +- dao层代码密度低,dao层代码尽量通用,以工具类形式使用。便于代码重用 +- service层代码密度高 通过组合复用原则使用dao层工具类,实现业务逻辑 +- controller层代码密度低 只负责简单的数据接受和转发。以及页面跳转的控制 + + + ## 示例 -```java -1. 项目案例:www.000oo1.com/ssm/cms/ -2. 默认账号/密码:admin/123 -``` \ No newline at end of file + +* www.000oo1.com/ssm/cms/ +* 默认账号/密码:admin/123 + + + From de74cce68deb91bb31e21ec1e370ea08b153aa47 Mon Sep 17 00:00:00 2001 From: qi Date: Sun, 11 Oct 2020 01:29:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lq/cms/web/sys/OssController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/lq/cms/web/sys/OssController.java b/src/main/java/com/lq/cms/web/sys/OssController.java index a42f1e4..0ed49f8 100644 --- a/src/main/java/com/lq/cms/web/sys/OssController.java +++ b/src/main/java/com/lq/cms/web/sys/OssController.java @@ -1,4 +1,15 @@ package com.lq.cms.web.sys; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * oss 控制类 + * @author qi + */ +@Controller +@RequestMapping("/sys/oss") public class OssController { + + }