实现用户信息修改页面session传值
This commit is contained in:
@@ -6,6 +6,7 @@ import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@@ -31,6 +32,12 @@ public class DataController {
|
||||
@Autowired
|
||||
private HomeworkService homeworkService;
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Autowired
|
||||
private VUserfileService vUserfileService;
|
||||
|
||||
@GetMapping("/home/findAllHomework")
|
||||
public List<VWorkDetail> findAllHomework(){
|
||||
List<VWorkDetail> homeworks = workDetailService.findAll();
|
||||
@@ -90,4 +97,15 @@ public class DataController {
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
}
|
||||
|
||||
@GetMapping("/home/findStudentInCourseFile")
|
||||
public List<VUserfile> findStudentInCourseFile(
|
||||
@RequestParam(value = "Folder") String Folder,@RequestParam(value = "CourseName") String CourseName){
|
||||
List<VUserfile> files = vUserfileService.findByWorkFolderAndCourseName(Folder,CourseName);
|
||||
if (files!=null){
|
||||
return files;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.fjy.spring.controller;
|
||||
|
||||
import com.fjy.spring.constant.GlobalConstant;
|
||||
import com.fjy.spring.domain.TbFile;
|
||||
import com.fjy.spring.domain.TbLog;
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.FileService;
|
||||
import com.fjy.spring.service.LogService;
|
||||
import com.fjy.spring.untils.FormatFileSizeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -12,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -30,6 +33,12 @@ public class UpLoadController {
|
||||
@Autowired
|
||||
private FileService fileService;//文件相关数据库操作
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
@Resource
|
||||
HttpServletRequest httpServletRequest;
|
||||
|
||||
@GetMapping("/toOneUpload")
|
||||
public String toOneUpload() {
|
||||
return "oneUpload";
|
||||
@@ -145,7 +154,9 @@ public class UpLoadController {
|
||||
|
||||
for (MultipartFile file : files.values()) {
|
||||
String filename = file.getOriginalFilename();
|
||||
File targetFile = new File(uploadUrl + filename);
|
||||
String suffix = "."+filename.substring(filename.lastIndexOf(".") + 1);//获取文件后缀
|
||||
|
||||
File targetFile = new File(uploadUrl + user.getColstudentno()+user.getColrealname()+suffix);
|
||||
|
||||
System.out.println("文件上传到: " + uploadUrl + filename);
|
||||
System.out.println("文件大小: " + new FormatFileSizeUtil().GetFileSize(file.getSize()));
|
||||
@@ -153,11 +164,21 @@ public class UpLoadController {
|
||||
|
||||
TbFile tbFile = new TbFile();
|
||||
tbFile.setColfilesize(new FormatFileSizeUtil().GetFileSize(file.getSize()));
|
||||
tbFile.setColfilename(filename);
|
||||
tbFile.setColfilename(user.getColstudentno()+user.getColrealname()+suffix);
|
||||
tbFile.setColtime(dateNowStr);
|
||||
tbFile.setColfilepath(uploadUrl + filename);
|
||||
tbFile.setColrealname(filename);
|
||||
tbFile.setColfilepath(uploadUrl + user.getColstudentno()+user.getColrealname()+suffix);//文件自动学号+姓名命名
|
||||
tbFile.setColip(request.getRemoteAddr());
|
||||
tbFile.setColuserid(user.getColuserid());
|
||||
tbFile.setCourseName(courseName);
|
||||
tbFile.setWorkFolder(folder);
|
||||
|
||||
TbLog log = new TbLog();
|
||||
log.setUserid(user.getColuserid());
|
||||
log.setColtime(dateNowStr);
|
||||
log.setColip(httpServletRequest.getRemoteAddr());
|
||||
log.setColheader(user.getColname()+"上传了"+filename+"文件");
|
||||
logService.addLogRec(log);
|
||||
|
||||
if (fileService.addFile(tbFile))
|
||||
System.out.println("记录写入数据库成功");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.fjy.spring.domain;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
@@ -23,6 +24,10 @@ public class TbFile {
|
||||
private String colfilesize;
|
||||
|
||||
private String colfilepath;
|
||||
@Column(name = "coursename")
|
||||
private String courseName;
|
||||
@Column(name = "workfolder")
|
||||
private String workFolder;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -35,6 +40,22 @@ public class TbFile {
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public String getWorkFolder() {
|
||||
return workFolder;
|
||||
}
|
||||
|
||||
public void setWorkFolder(String workFolder) {
|
||||
this.workFolder = workFolder;
|
||||
}
|
||||
|
||||
public String getColtime() {
|
||||
return coltime;
|
||||
}
|
||||
|
||||
126
src/main/java/com/fjy/spring/domain/VUserfile.java
Normal file
126
src/main/java/com/fjy/spring/domain/VUserfile.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.fjy.spring.domain;
|
||||
|
||||
import org.hibernate.annotations.Immutable;
|
||||
import org.hibernate.annotations.Subselect;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Immutable
|
||||
@Subselect("SELECT * FROM v_userfile")
|
||||
public class VUserfile {
|
||||
@Id
|
||||
private int colfileid;
|
||||
|
||||
private String colstudentno;
|
||||
|
||||
private String coltime;
|
||||
|
||||
private String colip;
|
||||
|
||||
private String colrealname;
|
||||
|
||||
private String colfilename;
|
||||
|
||||
private String colfilesize;
|
||||
|
||||
private String colfilepath;
|
||||
@Column(name = "coursename")
|
||||
private String courseName;
|
||||
@Column(name = "workfolder")
|
||||
private String workFolder;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TbFile{" +
|
||||
"colip='" + colip + '\'' +
|
||||
", colrealname='" + colrealname + '\'' +
|
||||
", colfilename='" + colfilename + '\'' +
|
||||
", colfilesize='" + colfilesize + '\'' +
|
||||
", colfilepath='" + colfilepath + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public String getWorkFolder() {
|
||||
return workFolder;
|
||||
}
|
||||
|
||||
public void setWorkFolder(String workFolder) {
|
||||
this.workFolder = workFolder;
|
||||
}
|
||||
|
||||
public String getColtime() {
|
||||
return coltime;
|
||||
}
|
||||
|
||||
public void setColtime(String coltime) {
|
||||
this.coltime = coltime;
|
||||
}
|
||||
|
||||
public int getColfileid() {
|
||||
return colfileid;
|
||||
}
|
||||
|
||||
public void setColfileid(int colfileid) {
|
||||
this.colfileid = colfileid;
|
||||
}
|
||||
|
||||
public String getColstudentno() {
|
||||
return colstudentno;
|
||||
}
|
||||
|
||||
public void setColstudentno(String colstudentno) {
|
||||
this.colstudentno = colstudentno;
|
||||
}
|
||||
|
||||
public String getColip() {
|
||||
return colip;
|
||||
}
|
||||
|
||||
public void setColip(String colip) {
|
||||
this.colip = colip;
|
||||
}
|
||||
|
||||
public String getColrealname() {
|
||||
return colrealname;
|
||||
}
|
||||
|
||||
public void setColrealname(String colrealname) {
|
||||
this.colrealname = colrealname;
|
||||
}
|
||||
|
||||
public String getColfilename() {
|
||||
return colfilename;
|
||||
}
|
||||
|
||||
public void setColfilename(String colfilename) {
|
||||
this.colfilename = colfilename;
|
||||
}
|
||||
|
||||
public String getColfilesize() {
|
||||
return colfilesize;
|
||||
}
|
||||
|
||||
public void setColfilesize(String colfilesize) {
|
||||
this.colfilesize = colfilesize;
|
||||
}
|
||||
|
||||
public String getColfilepath() {
|
||||
return colfilepath;
|
||||
}
|
||||
|
||||
public void setColfilepath(String colfilepath) {
|
||||
this.colfilepath = colfilepath;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/*@Configuration*/
|
||||
@Configuration
|
||||
public class WebAppConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,4 +8,6 @@ import java.util.Optional;
|
||||
|
||||
public interface TbFileRepository extends JpaRepository<TbFile,Integer>{
|
||||
public List<TbFile> findByColfilename(String name);
|
||||
|
||||
public List<TbFile> findByWorkFolderAndCourseName(String workFolder,String courseName);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.fjy.spring.repository;
|
||||
|
||||
import com.fjy.spring.domain.TbStudent;
|
||||
import com.fjy.spring.domain.VUserfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface TbStudentRepository extends JpaRepository<TbStudent,Integer> {
|
||||
import java.util.List;
|
||||
|
||||
public interface TbStudentRepository extends JpaRepository<TbStudent,Integer> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.fjy.spring.repository;
|
||||
|
||||
|
||||
import com.fjy.spring.domain.VUserfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface VUserfileRepository extends JpaRepository<VUserfile,Integer> {
|
||||
|
||||
public List<VUserfile> findByWorkFolderAndCourseName(String workFolder,String courseName);
|
||||
}
|
||||
@@ -43,4 +43,8 @@ public class FileService {
|
||||
tbFileRepository.deleteById(file.getColfileid());
|
||||
}
|
||||
|
||||
public List<TbFile> findByWorkFolderAndCourseName(String workFolder,String courseName){
|
||||
return tbFileRepository.findByWorkFolderAndCourseName(workFolder,courseName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
16
src/main/java/com/fjy/spring/service/StudentService.java
Normal file
16
src/main/java/com/fjy/spring/service/StudentService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.fjy.spring.service;
|
||||
|
||||
import com.fjy.spring.domain.TbStudent;
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.repository.TbStudentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StudentService {
|
||||
@Autowired
|
||||
private TbStudentRepository tbStudentRepository;
|
||||
|
||||
}
|
||||
@@ -43,4 +43,5 @@ public class UserService {
|
||||
public List<TbUser> findAllUser(){
|
||||
return tbUserRepository.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
18
src/main/java/com/fjy/spring/service/VUserfileService.java
Normal file
18
src/main/java/com/fjy/spring/service/VUserfileService.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.fjy.spring.service;
|
||||
|
||||
import com.fjy.spring.domain.VUserfile;
|
||||
import com.fjy.spring.repository.VUserfileRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class VUserfileService {
|
||||
@Autowired
|
||||
private VUserfileRepository vUserfileRepository;
|
||||
|
||||
public List<VUserfile> findByWorkFolderAndCourseName(String workFolder, String courseName) {
|
||||
return vUserfileRepository.findByWorkFolderAndCourseName(workFolder, courseName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user