提交 c7d6feb0 编写于 作者: 7 7wc98#14

commit

上级 2628748c
......@@ -8,6 +8,11 @@ import com.pyc.campus.domain.Grade;
import com.pyc.campus.domain.Msg;
import com.pyc.campus.domain.Question;
import com.pyc.campus.domain.Student;
import com.pyc.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.UserDetails;
......@@ -39,13 +44,16 @@ public class AdminController {
final QuestionRepository questionRepository;
final SysUserRepository sysUserRepository;
final StudentService studentService;
public AdminController(StudentRepository studentRepository,
GradeRepository gradeRepository,SysUserRepository sysUserRepository,
QuestionRepository questionRepository){
GradeRepository gradeRepository, SysUserRepository sysUserRepository,
QuestionRepository questionRepository, StudentService studentService){
this.studentRepository = studentRepository;
this.gradeRepository = gradeRepository;
this.sysUserRepository = sysUserRepository;
this.questionRepository = questionRepository;
this.studentService = studentService;
}
@RequestMapping("/admin")
public String admin(Model model,HttpSession session){
......@@ -57,25 +65,35 @@ public class AdminController {
}
@RequestMapping("/delStuByStuId")
public String delStuByStuId(Model model, HttpSession session, @RequestParam(value = "studentId", required = false)String stuId){
public String delStuByStuId(Model model, HttpSession session,
@RequestParam(value = "studentId", required = false)String stuId,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
studentRepository.delByStudentID(stuId);
sysUserRepository.delByUsername(stuId);
List<Student> students = studentRepository.findAll();
Page<Student> students = studentService.getStudentList(pageNum,pageSize);
model.addAttribute("students", students);
model.addAttribute("prefix","/delStuByStuId");
return "page/ManageUser";
}
@RequestMapping("/manageUser")
public String findUserExceptCurUser(Model model,HttpSession session){
List<Student> students = studentRepository.findAll();
public String findUserExceptCurUser(Model model,HttpSession session,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
Page<Student> students = studentService.getStudentList(pageNum,pageSize);
model.addAttribute("prefix","/manageUser");
model.addAttribute("students", students);
return "page/ManageUser";
}
@RequestMapping("/findUserByStudentIDLike")
public String findUserByStudentIDLike(Model model, HttpSession session,
@RequestParam(value = "ClassPrefix", required = false)String classPrefix){
List<Student> students = studentRepository.query01(classPrefix+'%');
@RequestParam(value = "ClassPrefix", required = false)String classPrefix,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
Page<Student> students = studentService.getStudentListByStuIdLike(pageNum,pageSize,classPrefix);
model.addAttribute("students", students);
model.addAttribute("prefix","/findUserByStudentIDLike");
return "page/ManageUser";
}
......
......@@ -4,6 +4,11 @@ import com.pyc.campus.config.MailConfig;
import com.pyc.campus.dao.QuestionRepository;
import com.pyc.campus.domain.Msg;
import com.pyc.campus.domain.Question;
import com.pyc.campus.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
......@@ -31,20 +36,29 @@ public class QuestionController {
final QuestionRepository questionRepository;
public QuestionController(QuestionRepository questionRepository){
final QuestionService questionService;
public QuestionController(QuestionRepository questionRepository, QuestionService questionService){
this.questionRepository = questionRepository;
this.questionService = questionService;
}
@RequestMapping("/toBrowserQuestion")
public String toBrowserQuestion(Model model, HttpSession session){
List<Question> questions = questionRepository.findAll();
public String toBrowserQuestion(Model model, HttpSession session,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
Page<Question> questions = questionService.getQuestionList(pageNum,pageSize);
model.addAttribute("prefix","/toBrowserQuestion");
model.addAttribute("questions", questions);
return "page/BrowserQuestion";
}
@RequestMapping("/queryByQuestionType")
public String queryByQuestionType(Model model, HttpSession session,
@RequestParam(value = "TypeOfQuestion", required = false)String type){
List<Question> questions = questionRepository.findAllByType(type);
@RequestParam(value = "TypeOfQuestion", required = false)String type,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
Page<Question> questions = questionService.getQuestionListByType(pageNum,pageSize,type);
model.addAttribute("prefix","/queryByQuestionType");
model.addAttribute("questions", questions);
return "page/BrowserQuestion";
}
......
......@@ -3,6 +3,11 @@ package com.pyc.campus.controller;
import com.pyc.campus.dao.StudentRepository;
import com.pyc.campus.domain.Msg;
import com.pyc.campus.domain.Student;
import com.pyc.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.UserDetails;
......@@ -31,8 +36,12 @@ public class StudentController {
final
StudentRepository studentRepository;
public StudentController(StudentRepository studentRepository){
final
StudentService studentService;
public StudentController(StudentRepository studentRepository, StudentService studentService){
this.studentRepository = studentRepository;
this.studentService = studentService;
}
@RequestMapping("/userCenter")
......@@ -123,7 +132,9 @@ public class StudentController {
@RequestMapping("/saveFrozenInTrue")
public String saveFrozenInTrue(Model model,HttpSession session,
@RequestParam(value = "studentId", required = false)String studentID){
@RequestParam(value = "studentId", required = false)String studentID,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
int t = studentRepository.saveFrozen(true,studentID);
if(t!=0){
System.out.println("更新成功!");
......@@ -132,7 +143,8 @@ public class StudentController {
{
System.out.println("更新失败!");
}
List<Student> students = studentRepository.findAll();
Page<Student> students = studentService.getStudentList(pageNum,pageSize);
model.addAttribute("prefix","/saveFrozenInTrue");
model.addAttribute("students", students);
return "page/ManageUser";
......@@ -140,7 +152,9 @@ public class StudentController {
@RequestMapping("/saveFrozenInFalse")
public String saveFrozenInFalse(Model model,HttpSession session,
@RequestParam(value = "studentId", required = false)String studentID){
@RequestParam(value = "studentId", required = false)String studentID,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
int t = studentRepository.saveFrozen(false,studentID);
if(t!=0){
......@@ -150,7 +164,8 @@ public class StudentController {
{
System.out.println("更新失败!");
}
List<Student> students = studentRepository.findAll();
Page<Student> students = studentService.getStudentList(pageNum,pageSize);
model.addAttribute("prefix","/saveFrozenInFalse");
model.addAttribute("students", students);
return "page/ManageUser";
......
......@@ -9,11 +9,13 @@
package com.pyc.campus.dao;
import com.pyc.campus.domain.Question;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface QuestionRepository extends JpaRepository<Question, Long> {
List<Question> findAll();
List<Question> findAllByType(String type);
Page<Question> findAllByType(String type, Pageable p);
}
......@@ -8,6 +8,8 @@
package com.pyc.campus.dao;
import com.pyc.campus.domain.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
......@@ -41,10 +43,9 @@ public interface StudentRepository extends JpaRepository<Student,Long> {
@Query("select s from Student s where s.studentID=?1")
Student getOnlineStatus(String studentID);
// 根据Student ID前缀查询
@Modifying
@Transactional
@Query("select s from Student s where s.studentID like ?1")
List<Student> query01(String classPrefix);
Page<Student> query01(String classPrefix, Pageable p);
@Modifying
@Transactional
@Query("delete from Student where studentID=?1")
......
......@@ -15,6 +15,7 @@ import java.io.Serializable;
@Entity
public class Grade implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
long id;
......
......@@ -7,19 +7,27 @@
package com.pyc.campus.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
@Entity
public class Question {
public class Question implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long id;
@Column(nullable = true,unique = true)
private String publisher; // 申请人
@Column(nullable = true,unique = true)
private String mail; // 邮箱
@Column(nullable = true,unique = true)
private String type; // 问题类型
@Column(nullable = true,unique = true)
private String content; // 问题内容
@Column(nullable = true,unique = true)
private String reward; // 悬赏
public Question(){
super();
......@@ -82,4 +90,16 @@ public class Question {
public String getType() {
return type;
}
@Override
public String toString() {
return "Question{" +
"id=" + id +
", publisher='" + publisher + '\'' +
", mail='" + mail + '\'' +
", type='" + type + '\'' +
", content='" + content + '\'' +
", reward='" + reward + '\'' +
'}';
}
}
......@@ -7,22 +7,33 @@
package com.pyc.campus.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
@Entity
public class Student {
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@Column(nullable = true,unique = true)
private String name;
@Column(nullable = true,unique = true)
private String studentID;
@Column(nullable = true,unique = true)
private String password;
@Column(nullable = true,unique = true)
private String weChat;
@Column(nullable = true,unique = true)
private String QQ;
@Column(nullable = true,unique = true)
private int admin;
@Column(nullable = true,unique = true)
private boolean onlineStatus;
@Column(nullable = true,unique = true)
private boolean frozen;
public Student() {
......@@ -112,4 +123,19 @@ public class Student {
public String getWeChat() {
return weChat;
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", studentID='" + studentID + '\'' +
", password='" + password + '\'' +
", weChat='" + weChat + '\'' +
", QQ='" + QQ + '\'' +
", admin=" + admin +
", onlineStatus=" + onlineStatus +
", frozen=" + frozen +
'}';
}
}
package com.pyc.campus.service;
import com.pyc.campus.domain.Question;
import org.springframework.data.domain.Page;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file QuestionService
* @pack com.pyc.campus.service
* @date 2021/1/29
* @time 14:58
* @E-mail 2923616405@qq.com
**/
public interface QuestionService {
Page<Question> getQuestionList(int pageNum, int pageSize);
Page<Question> getQuestionListByType(int pageNum, int pageSize, String type);
}
package com.pyc.campus.service;
import com.pyc.campus.domain.Student;
import org.springframework.data.domain.Page;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file StudentService
* @pack com.pyc.campus.service
* @date 2021/1/29
* @time 14:44
* @E-mail 2923616405@qq.com
**/
public interface StudentService {
Page<Student> getStudentList(int pageNum, int pageSize);
Page<Student> getStudentListByStuIdLike(int pageNum, int pageSize, String like);
}
package com.pyc.campus.service.impl;
import com.pyc.campus.dao.QuestionRepository;
import com.pyc.campus.domain.Question;
import com.pyc.campus.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file QuestionServiceImpl
* @pack com.pyc.campus.service.impl
* @date 2021/1/29
* @time 15:00
* @E-mail 2923616405@qq.com
**/
@Service
public class QuestionServiceImpl implements QuestionService {
final QuestionRepository questionRepository;
public QuestionServiceImpl(QuestionRepository questionRepository) {
this.questionRepository = questionRepository;
}
@Override
public Page<Question> getQuestionList(int pageNum, int pageSize) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return questionRepository.findAll(pageable);
}
@Override
public Page<Question> getQuestionListByType(int pageNum, int pageSize, String type) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return questionRepository.findAllByType(type,pageable);
}
}
package com.pyc.campus.service.impl;
import com.pyc.campus.dao.StudentRepository;
import com.pyc.campus.domain.Student;
import com.pyc.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file StudentServiceImpl
* @pack com.pyc.campus.service.impl
* @date 2021/1/29
* @time 14:46
* @E-mail 2923616405@qq.com
**/
@Service
public class StudentServiceImpl implements StudentService {
final
StudentRepository studentRepository;
public StudentServiceImpl(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
@Override
public Page<Student> getStudentList(int pageNum, int pageSize) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return studentRepository.findAll(pageable);
}
@Override
public Page<Student> getStudentListByStuIdLike(int pageNum, int pageSize, String like) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return studentRepository.query01(like,pageable);
}
}
......@@ -94,6 +94,7 @@
<table class="table table-striped">
<thead>
<tr>
<th>序号</th>
<th>发布者</th>
<th>邮箱</th>
<th>问题类型</th>
......@@ -103,6 +104,7 @@
</thead>
<tbody th:if="${not #lists.isEmpty(questions)}">
<tr th:each="question:${questions}">
<th scope="row" th:text="${questionStat.index + 1}">1</th>
<td th:text="${question.getPublisher()}"></td>
<td th:text="${question.mail}"></td>
<td th:text="${question.type}"></td>
......@@ -111,6 +113,40 @@
</tr>
</tbody>
</table>
<div class="modal-footer no-margin-top">
<ul class="pagination pull-right no-margin">
<!-- 首页 -->
<li>
<a th:href="${prefix}+'?pageNum=0'">首页</a>
</li>
<!-- 上一页 -->
<li th:if="${questions.hasPrevious()}">
<!--/*@thymesVar id="previousPageable" type="org.springframework.data.domain.Page"*/-->
<a th:href="${prefix}+'?pageNum=' + ${questions.previousPageable().getPageNumber()}" th:text="上一页"></a>
</li>
<!-- 中间页 -->
<li th:each="pageNum:${#numbers.sequence(0, questions.getTotalPages() - 1)}">
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum ne questions.pageable.getPageNumber()}"></a>
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum eq questions.pageable.getPageNumber()}"
th:style="'font-weight:bold;background: #6faed9;'"></a>
</li>
<!-- 下一页 -->
<li th:if="${questions.hasNext()}">
<a th:href="${prefix}+'?pageNum=' + ${questions.nextPageable().getPageNumber()}" th:text="下一页"></a>
</li>
<!-- 尾页 -->
<li>
<a th:href="${prefix}+'?pageNum=' + ${questions.getTotalPages() - 1}">尾页</a>
</li>
</ul>
</div>
</div>
</div>
</div>
......
......@@ -154,6 +154,7 @@
<table class="table table-striped table-hover">
<thead>
<tr>
<th>序号</th>
<th>姓名</th>
<th>学号</th>
<th>QQ</th>
......@@ -164,6 +165,7 @@
</thead>
<tbody th:if="${not #lists.isEmpty(students)}">
<tr th:each="student:${students}">
<th scope="row" th:text="${studentStat.index + 1}">1</th>
<td th:text="${student.getName()}"></td>
<td th:text="${student.getStudentID()}"></td>
<td th:text="${student.getQQ()}"></td>
......@@ -173,6 +175,40 @@
</tr>
</tbody>
</table>
<div class="modal-footer no-margin-top">
<ul class="pagination pull-right no-margin">
<!-- 首页 -->
<li>
<a th:href="${prefix}+'?pageNum=0'">首页</a>
</li>
<!-- 上一页 -->
<li th:if="${students.hasPrevious()}">
<!--/*@thymesVar id="previousPageable" type="org.springframework.data.domain.Page"*/-->
<a th:href="${prefix}+'?pageNum=' + ${students.previousPageable().getPageNumber()}" th:text="上一页"></a>
</li>
<!-- 中间页 -->
<li th:each="pageNum:${#numbers.sequence(0, students.getTotalPages() - 1)}">
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum ne students.pageable.getPageNumber()}"></a>
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum eq students.pageable.getPageNumber()}"
th:style="'font-weight:bold;background: #6faed9;'"></a>
</li>
<!-- 下一页 -->
<li th:if="${students.hasNext()}">
<a th:href="${prefix}+'?pageNum=' + ${students.nextPageable().getPageNumber()}" th:text="下一页"></a>
</li>
<!-- 尾页 -->
<li>
<a th:href="${prefix}+'?pageNum=' + ${students.getTotalPages() - 1}">尾页</a>
</li>
</ul>
</div>
</div>
<form class="form-inline" name="form2" method="post" th:action="@{/delStuByStuId}">
<div class="form-group">
......
......@@ -149,8 +149,11 @@
<!-- 中间页 -->
<li th:each="pageNum:${#numbers.sequence(0, gradeItems.getTotalPages() - 1)}">
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}" th:if="${pageNum ne gradeItems.pageable.getPageNumber()}"></a>
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}" th:if="${pageNum eq gradeItems.pageable.getPageNumber()}" th:style="'font-weight:bold;background: #6faed9;'"></a>
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum ne gradeItems.pageable.getPageNumber()}"></a>
<a th:href="${prefix}+'?pageNum=' + ${pageNum}" th:text="${pageNum + 1}"
th:if="${pageNum eq gradeItems.pageable.getPageNumber()}"
th:style="'font-weight:bold;background: #6faed9;'"></a>
</li>
<!-- 下一页 -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册