From 99ec5c25356e66758f9030e6b1d89f73b2a7db71 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Tue, 30 Oct 2018 09:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lq/api/package-info.java | 1 - .../com/lq/api/service/SysFileService.java | 9 +++++ .../api/service/impl/SysFileServiceImpl.java | 22 ++++++++++++ src/main/java/com/lq/api/vo/SysFileVo.java | 6 ++++ .../com/lq/api/web/SysFileController.java | 35 ++++++++++++++++--- src/main/resources/spring/spring-shiro.xml | 2 +- .../WEB-INF/views/jsp/cms/sys/menu/edit.jsp | 8 ++++- 7 files changed, 76 insertions(+), 7 deletions(-) delete mode 100644 src/main/java/com/lq/api/package-info.java create mode 100644 src/main/java/com/lq/api/service/SysFileService.java create mode 100644 src/main/java/com/lq/api/service/impl/SysFileServiceImpl.java create mode 100644 src/main/java/com/lq/api/vo/SysFileVo.java diff --git a/src/main/java/com/lq/api/package-info.java b/src/main/java/com/lq/api/package-info.java deleted file mode 100644 index da9ca92..0000000 --- a/src/main/java/com/lq/api/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.lq.api; \ No newline at end of file diff --git a/src/main/java/com/lq/api/service/SysFileService.java b/src/main/java/com/lq/api/service/SysFileService.java new file mode 100644 index 0000000..f1431ce --- /dev/null +++ b/src/main/java/com/lq/api/service/SysFileService.java @@ -0,0 +1,9 @@ +package com.lq.api.service; + +import com.lq.code.service.BaseService; +import com.lq.entity.SysFile; + +public interface SysFileService extends BaseService{ + + +} diff --git a/src/main/java/com/lq/api/service/impl/SysFileServiceImpl.java b/src/main/java/com/lq/api/service/impl/SysFileServiceImpl.java new file mode 100644 index 0000000..64ad2bb --- /dev/null +++ b/src/main/java/com/lq/api/service/impl/SysFileServiceImpl.java @@ -0,0 +1,22 @@ +package com.lq.api.service.impl; + +import com.lq.api.service.SysFileService; +import com.lq.code.dao.BaseDao; +import com.lq.code.service.BaseService; +import com.lq.code.service.impl.BaseServiceImpl; +import com.lq.dao.SysFileDao; +import com.lq.entity.SysFile; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SysFileServiceImpl extends BaseServiceImpl implements SysFileService { + + @Autowired + private SysFileDao sysFileDao; + + @Override + public BaseDao getBaseDao() { + return sysFileDao; + } +} diff --git a/src/main/java/com/lq/api/vo/SysFileVo.java b/src/main/java/com/lq/api/vo/SysFileVo.java new file mode 100644 index 0000000..0960756 --- /dev/null +++ b/src/main/java/com/lq/api/vo/SysFileVo.java @@ -0,0 +1,6 @@ +package com.lq.api.vo; + +public class SysFileVo { + + +} diff --git a/src/main/java/com/lq/api/web/SysFileController.java b/src/main/java/com/lq/api/web/SysFileController.java index 8ac5b5f..fec17eb 100644 --- a/src/main/java/com/lq/api/web/SysFileController.java +++ b/src/main/java/com/lq/api/web/SysFileController.java @@ -1,8 +1,12 @@ package com.lq.api.web; +import com.lq.api.service.SysFileService; +import com.lq.cms.emun.StatusTypeEnum; import com.lq.code.entity.AjaxResult; import com.lq.code.util.FileUtil; import com.lq.entity.SysFile; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -11,8 +15,15 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + @Controller @RequestMapping("/file") public class SysFileController { @@ -20,11 +31,13 @@ public class SysFileController { @Value("${file.upload}") private String FILE_LOAD_PATH; + @Autowired + private SysFileService sysFileService; @RequestMapping("/upload") @ResponseBody - public Object upload(@RequestParam("files")MultipartFile[] files){ + public Object upload(@RequestParam("files")MultipartFile[] files) throws IOException { AjaxResult ajaxResult = new AjaxResult(); ajaxResult.setMsg("上传成功"); Date nowTime = new Date(); @@ -33,14 +46,28 @@ public class SysFileController { if (!fileDir.exists()){ fileDir.mkdirs(); } + List sysFileList = new ArrayList<>(); for (MultipartFile multipartFile:files){ + String originalFileName = multipartFile.getOriginalFilename(); + Path path = FileSystems.getDefault().getPath(FILE_LOAD_PATH+sdf.format(nowTime),originalFileName); + //上传文件 + multipartFile.transferTo(path); + //保存文件信息 SysFile sysFile = new SysFile(); sysFile.setCreateTime(nowTime); - String fileType = FileUtil.getFileType(multipartFile.getName()); + String fileType = FileUtil.getFileType(originalFileName); sysFile.setFileType(fileType); - sysFile.setFileName(multipartFile.getName()); - + sysFile.setFileName(originalFileName); + sysFile.setPath(sdf.format(nowTime)+"/"+originalFileName); + sysFile.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); + sysFileService.save(sysFile); + sysFileList.add(sysFile); } + ajaxResult.setData(sysFileList); return ajaxResult; } + + + + } diff --git a/src/main/resources/spring/spring-shiro.xml b/src/main/resources/spring/spring-shiro.xml index 275f374..b6749fb 100644 --- a/src/main/resources/spring/spring-shiro.xml +++ b/src/main/resources/spring/spring-shiro.xml @@ -39,7 +39,7 @@ - + diff --git a/src/main/webapp/WEB-INF/views/jsp/cms/sys/menu/edit.jsp b/src/main/webapp/WEB-INF/views/jsp/cms/sys/menu/edit.jsp index fb04b1a..fe41b70 100644 --- a/src/main/webapp/WEB-INF/views/jsp/cms/sys/menu/edit.jsp +++ b/src/main/webapp/WEB-INF/views/jsp/cms/sys/menu/edit.jsp @@ -53,6 +53,11 @@ + @@ -91,7 +96,8 @@ }else { isSelect = ''; } - html+= ''; + html+= ''; + // html+= ''; } $("#menuIco").append(html); }