实现用户信息修改页面session传值

This commit is contained in:
F嘉阳
2018-02-21 12:57:49 +08:00
parent 4335a6764e
commit b6def717f4
18 changed files with 407 additions and 100 deletions

View File

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

View File

@@ -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("记录写入数据库成功");

View File

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

View 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;
}
}

View File

@@ -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 {
/**

View File

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

View File

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

View File

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

View File

@@ -43,4 +43,8 @@ public class FileService {
tbFileRepository.deleteById(file.getColfileid());
}
public List<TbFile> findByWorkFolderAndCourseName(String workFolder,String courseName){
return tbFileRepository.findByWorkFolderAndCourseName(workFolder,courseName);
}
}

View 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;
}

View File

@@ -43,4 +43,5 @@ public class UserService {
public List<TbUser> findAllUser(){
return tbUserRepository.findAll();
}
}

View 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);
}
}

View File

@@ -228,6 +228,27 @@ var Main = {
/*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/
window.open("http://localhost:8080/cms/download/dodownload?fileId=" + row.colfileid);
},
handleDelete(row) {
axios({
url: 'http://localhost:8080/cms/home/filedelete',
method: 'post',
data: {
fileid: row.colfileid
},
transformRequest: [function (data) {
// Do whatever you want to transform the data
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
this.openNotiSuccess("成功","删除成功!");
},
handlePreview(file) {
console.log(file);
},

View File

@@ -3,8 +3,10 @@ var Main = {
return {
activeIndex: '1',
formInline: {
user: '',
region: ''
name:'',
name2:'',
content: '',
folder: ''
},
homeworkData: [
{
@@ -17,6 +19,15 @@ var Main = {
folder: "第一次作业"
}
],
homeworkFormData:[
{
courseNo: 1,
courseName: "信息安全",
courseTime: "2018-02-06 20:42:28.0",
teacherusername: "FJY",
teacherrealname: "root"
}
],
multipleSelection: []
}
},
@@ -31,6 +42,14 @@ var Main = {
.catch(function (error) {
console.log(error);
});
axios.get('http://localhost:8080/cms/home/findallvhomework')
.then(function (response) {
console.log(response.data);
that.homeworkData = response.data;
})
.catch(function (error) {
console.log(error);
});
})
},
methods: {

View File

@@ -1,3 +1,17 @@
var dt = new Date();
var month = dt.getMonth()+1;
var day = dt.getDate();
var year = dt.getFullYear();
var cur = year + '-' + month + '-' + day;
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
return iDays
}
var Main = {
data() {
var checkName = (rule, value, callback) => {
@@ -37,12 +51,8 @@ var Main = {
return {
activeIndex: '1',
ruleForm2: {
colname: '',
colpassword: '',
checkPass: '',
colstudentno: '',
colrealname: '',
colemail: ''
},
rules2: {
colpassword: [
@@ -94,10 +104,41 @@ var Main = {
}
},
methods: {
submitForm(formName) {
openNotiSuccess(title, content) {
this.$notify({
title: title,
message: content,
type: 'success'
});
},
limitTime(row){
return DateDiff(row.worktime.replace(/([^\s]+)\s.*/, "$1"), cur);
},
submitForm(formName, url) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
axios({
url: 'http://localhost:8080/cms/' + url,
method: 'post',
data: {
content: this.$refs.content.value
},
transformRequest: [function (data) {
// Do whatever you want to transform the data
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
console.log(this.$refs.content.value)
this.openNotiSuccess("成功", "修改成功!")
//this.$options.methods.openNotiSuccess.bind(this)();
//alert('submit!');
} else {
console.log('error submit!!');
return false;

View File

@@ -240,11 +240,11 @@
</el-table-column>
<el-table-column fixed="right" label="操作" width="150">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="success" plain
<el-button @click="handleDownload(scope.row)" type="success" plain
size="small">
下载
</el-button>
<el-button type="danger" plain size="small">删除</el-button>
<el-button type="danger" plain size="small" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table-column>

View File

@@ -1,19 +1,50 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:include="dist/thymeleaf/common_head :: header('课程管理')">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>作业管理</title>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!--<link rel="stylesheet" href="https://unpkg.com/element-ui@2.1.0/lib/theme-chalk/display.css">-->
<link rel="stylesheet" href="../../static/css/style.css">
</head>
<body>
<div th:insert="~{dist/thymeleaf/common_head :: #body_js}"></div>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<div id="app">
<el-container>
<el-container>
<el-header th:include="dist/thymeleaf/layout :: header"></el-header>
<el-header>
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
<el-menu-item index="1">首页</el-menu-item>
<el-submenu index="2">
<template slot="title">个人中心</template>
<el-menu-item index="2-1">选项1</el-menu-item>
<el-menu-item index="2-2">选项2</el-menu-item>
<el-menu-item index="2-3">选项3</el-menu-item>
</el-submenu>
<el-menu-item index="3" @click="ClickToJump('about')">关于</el-menu-item>
<el-menu-item index="4" @click="ClickToJump('feedback')">意见反馈</el-menu-item>
<el-menu-item index="5"><a href="login.jsp">登出</a></el-menu-item>
</el-menu>
</el-header>
<el-main>
<el-col :md="4" :lg="4" :xl="4" class="hidden-sm-and-down">
<el-row>
<el-card th:include="dist/thymeleaf/layout :: userbox"></el-card>
<el-row><el-card class="box-card">
<div slot="header" class="clearfix">
<span>用户名</span><br>
<span>学号</span>
</div>
<div class="item">
<el-button type="text" @click="ClickToJump('home')">首页</el-button><br>
<el-button type="text" @click="ClickToJump('user')">个人中心</el-button><br>
<el-button type="text" @click="ClickToJump('about')">关于</el-button><br>
<el-button type="text" @click="ClickToJump('feedback')">意见反馈</el-button>
</div>
</el-card>
</el-row>
<el-row>
<el-card th:include="dist/thymeleaf/layout :: adminbox"></el-card>
@@ -47,25 +78,24 @@
<h4>添加作业</h4>
<el-form :inline="true" :model="formInline" class="demo-form-inline">
<el-form-item label="作业名称">
<el-input v-model="formInline.user" placeholder="作业名称"></el-input>
<el-input v-model="formInline.name" placeholder="作业名称"></el-input>
</el-form-item>
<el-form-item label="模板文件名称">
<el-select v-model="formInline.region" placeholder="模板文件名称">
<el-select v-model="formInline.name" placeholder="模板文件名称">
<el-option label="区域一" value="shanghai"></el-option>
<el-option label="区域二" value="beijing"></el-option>
</el-select>
</el-form-item>
<el-form-item label="课程名称">
<el-select v-model="formInline.region" placeholder="课程名称">
<el-option label="区域一" value="shanghai"></el-option>
<el-option label="区域二" value="beijing"></el-option>
<el-form-item label="课程名称" :model="homeworkFormData">
<el-select v-model="homeworkFormData.courseName" placeholder="课程名称">
<el-option label="homeworkFormData.courseName" value="homeworkFormData.courseName"></el-option>
</el-select>
</el-form-item>
<el-form-item label="存储文件夹">
<el-input v-model="formInline.user" placeholder="存储文件夹"></el-input>
<el-input v-model="formInline.folder" placeholder="存储文件夹"></el-input>
</el-form-item>
<el-form-item label="作业内容">
<el-input v-model="formInline.user" placeholder="作业内容" type="textarea"></el-input>
<el-input v-model="formInline.content" placeholder="作业内容" type="textarea"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">添加</el-button>
@@ -84,7 +114,7 @@
</el-container>
</el-container>
</div>
<script th:src="@{/js/homework.js}"></script>
<script th:src="@{/js/common.js}"></script>
<script src="../../static/js/homework.js"></script>
<script src="../../static/js/common.js"></script>
</body>
</html>

View File

@@ -1,58 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>个人中心</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!--<link rel="stylesheet" href="https://unpkg.com/element-ui@2.1.0/lib/theme-chalk/display.css">-->
<link rel="stylesheet" href="../../static/css/style.css">
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:include="dist/thymeleaf/common_head :: header('个人中心')">
</head>
<body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<div th:insert="~{dist/thymeleaf/common_head :: #body_js}"></div>
<div id="app">
<el-container>
<el-container>
<el-header>
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
<el-menu-item index="1">首页</el-menu-item>
<el-submenu index="2">
<template slot="title">个人中心</template>
<el-menu-item index="2-1">选项1</el-menu-item>
<el-menu-item index="2-2">选项2</el-menu-item>
<el-menu-item index="2-3">选项3</el-menu-item>
</el-submenu>
<el-menu-item index="3" @click="ClickToJump('about')">关于</el-menu-item>
<el-menu-item index="4" @click="ClickToJump('feedback')">意见反馈</el-menu-item>
<el-menu-item index="5"><a href="login.jsp">登出</a></el-menu-item>
</el-menu>
</el-header>
<el-header th:include="dist/thymeleaf/layout :: header"></el-header>
<el-main>
<el-col :md="4" :lg="4" :xl="4" class="hidden-sm-and-down">
<el-row>
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>用户名</span><br>
<span>学号</span>
</div>
<div class="item">
<el-button type="text" @click="ClickToJump('home')">首页</el-button>
<br>
<el-button type="text" @click="ClickToJump('user')">个人中心</el-button>
<br>
<el-button type="text" @click="ClickToJump('about')">关于</el-button>
<br>
<el-button type="text" @click="ClickToJump('feedback')">意见反馈</el-button>
</div>
</el-card>
</el-row>
<el-card th:include="dist/thymeleaf/layout :: userbox"></el-card>
</el-col>
<el-col :md="13" :lg="13" :xl="13" :sm="18" :xs="23" :offset="1">
<el-row>
@@ -65,7 +24,7 @@
<el-form-item label="用户名"
prop="colname">
<el-input
v-model="ruleForm2.colname" name="colname"></el-input>
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colname}" name="colname"></el-input>
</el-form-item>
<el-form-item
label="密码" prop="colpassword">
@@ -82,21 +41,21 @@
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change' }
]">
<el-input v-model="ruleForm2.colemail" name="colemail"></el-input>
<el-input th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colemail}" name="colemail"></el-input>
</el-form-item>
<el-form-item label="学号"
prop="colstudentno">
<el-input
v-model="ruleForm2.colstudentno" name="colstudentno"></el-input>
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colstudentno}" name="colstudentno"></el-input>
</el-form-item>
<el-form-item label="真实姓名"
prop="colrealname">
<el-input
v-model="ruleForm2.colrealname" name="colrealname"></el-input>
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colrealname}" name="colrealname"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary"
native-type="submit">提交
@click="submitForm('feedbackForm','register/doregister')">提交
</el-button>
<el-button @click="resetForm('ruleForm2')">重置</el-button>
</el-form-item>
@@ -140,15 +99,11 @@
</el-row>
</el-col>
</el-main>
<el-footer>
<div class="footer">
© 2018 作业提交系统
</div>
</el-footer>
<el-footer th:include="dist/thymeleaf/layout :: footer"></el-footer>
</el-container>
</el-container>
</div>
<script src="../../static/js/user.js"></script>
<script src="../../static/js/common.js"></script>
<script th:src="@{/js/user.js}"></script>
<script th:src="@{/js/common.js}"></script>
</body>
</html>