新增文件上传功能接口

master
星期八 6 years ago
parent 2d899495a6
commit 99ec5c2535
  1. 1
      src/main/java/com/lq/api/package-info.java
  2. 9
      src/main/java/com/lq/api/service/SysFileService.java
  3. 22
      src/main/java/com/lq/api/service/impl/SysFileServiceImpl.java
  4. 6
      src/main/java/com/lq/api/vo/SysFileVo.java
  5. 35
      src/main/java/com/lq/api/web/SysFileController.java
  6. 2
      src/main/resources/spring/spring-shiro.xml
  7. 8
      src/main/webapp/WEB-INF/views/jsp/cms/sys/menu/edit.jsp

@ -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<SysFile>{
}

@ -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<SysFile> implements SysFileService {
@Autowired
private SysFileDao sysFileDao;
@Override
public BaseDao<SysFile> getBaseDao() {
return sysFileDao;
}
}

@ -0,0 +1,6 @@
package com.lq.api.vo;
public class SysFileVo {
}

@ -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<SysFile> 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;
}
}

@ -39,7 +39,7 @@
<!-- 保证该系统不会受到跨域的脚本操作供给 -->
<property name="httpOnly" value="true"/>
<!-- 定义Cookie的过期时间,单位为秒,如果设置为-1表示浏览器关闭,则Cookie消失 -->
<!-- <property name="maxAge" value="-1"/>-->
<property name="maxAge" value="-1"/>
</bean>
<!-- 定义会话管理器的操作 -->

@ -53,6 +53,11 @@
<select id="menuIco" class="easyui-combobox">
</select>
<!--
<div id="menuIco">
</div>
-->
</td>
</tr>
@ -91,7 +96,8 @@
}else {
isSelect = '';
}
html+= '<option value="'+valArray[i]+'" '+isSelect+'>'+valArray[i]+'</option>';
html+= '<option value="'+valArray[i]+'" '+isSelect+'>'+valArray[i]+'</option>';
// html+= '<i class='+valArray[i]+'></i>';
}
$("#menuIco").append(html);
}

Loading…
Cancel
Save