实现用户仅能查看自己提交的文件

This commit is contained in:
F嘉阳
2018-02-23 13:02:23 +08:00
parent c91ee252a3
commit a50c33375d
14 changed files with 783 additions and 106 deletions

View File

@@ -1,6 +1,7 @@
package com.fjy.spring.controller;
import com.fjy.spring.domain.TbFile;
import com.fjy.spring.domain.TbUser;
import com.fjy.spring.enums.ResultEnum;
import com.fjy.spring.exception.UserException;
import com.fjy.spring.service.FileService;
@@ -11,16 +12,22 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
@Controller
public class DownLoadController {
@Autowired
private FileService fileService;
@Resource
HttpServletRequest request;
/*@GetMapping("/download")
public String toDownloadPage(){
return "download/dodownload";
@@ -36,6 +43,19 @@ public class DownLoadController {
return null;
}
@GetMapping("/download/findone")
@ResponseBody
public List<TbFile> toDownloadOne(){
TbUser user = (TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
System.out.println(user.toString());
List<TbFile> files = fileService.findByColuserid(user.getColuserid());
//此处做空指针判断并抛出错误
if (files!=null)
return files;
new UserException(ResultEnum.EMPTY_DATA);
return null;
}
@RequestMapping("/download/dodownload")
public String download(@RequestParam Integer fileId , HttpServletRequest request, HttpServletResponse response){

View File

@@ -2,9 +2,16 @@ package com.fjy.spring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.support.SessionStatus;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Controller
public class NavController {
@Resource
HttpServletRequest request;
@GetMapping(value = {"index",""})
public String toLoginPage(){
return "login";
@@ -25,6 +32,13 @@ public class NavController {
return "/home/home";
}
@GetMapping(value = {"/logout"})
public String toLogOut(SessionStatus status){
//request.getSession().getAttribute(USER_SESSION_KEY).invalidate();
status.setComplete();
return "login";
}
@GetMapping(value = {"/home/feedback"})
public String toFeedbackPage(){
return "/home/feedback";
@@ -55,7 +69,6 @@ public class NavController {
return "/home/homework";
}
@GetMapping(value = {"/home/user"})
public String toUserPage(){
return "/home/user";

View File

@@ -7,7 +7,7 @@ import javax.persistence.*;
@Entity
@Immutable
@Subselect("SELECT * FROM v_log ORDER BY coltime LIMIT 0, 20")
@Subselect("SELECT * FROM v_log ORDER BY coltime DESC LIMIT 0, 20")
public class VLog {
@Id
private Integer logid;

View File

@@ -9,4 +9,6 @@ public interface TbFileRepository extends JpaRepository<TbFile,Integer>{
public List<TbFile> findByColfilename(String name);
public List<TbFile> findByWorkFolderAndCourseName(String workFolder,String courseName);
public List<TbFile> findByColuserid(Integer id);
}

View File

@@ -48,4 +48,8 @@ public class FileService {
return tbFileRepository.findByWorkFolderAndCourseName(workFolder,courseName);
}
public List<TbFile> findByColuserid(Integer id){
return tbFileRepository.findByColuserid(id);
}
}