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

commit

上级 bd2fa6dc
package com.pyc.campus.config;
import org.hibernate.dialect.MySQL8Dialect;
import org.springframework.stereotype.Component;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file MysqlConfig
* @pack com.pyc.campus.config
* @date 2021/1/29
* @time 10:27
* @E-mail 2923616405@qq.com
**/
@Component
@SuppressWarnings("decription")
public class MysqlConfig extends MySQL8Dialect {
@Override
public String getTableTypeString(){
return "ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
}
......@@ -5,12 +5,16 @@ import com.pyc.campus.dao.StudentRepository;
import com.pyc.campus.domain.Grade;
import com.pyc.campus.domain.Msg;
import com.pyc.campus.domain.Student;
import com.pyc.campus.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.List;
......@@ -29,23 +33,32 @@ import java.util.List;
@Controller
public class GradeController {
final
GradeService gradeService;
final GradeRepository gradeRepository;
final StudentRepository studentRepository;
public GradeController(GradeRepository gradeRepository,StudentRepository studentRepository){
public GradeController(GradeRepository gradeRepository, StudentRepository studentRepository,
GradeService gradeService){
this.gradeRepository = gradeRepository;
this.studentRepository = studentRepository;
this.gradeService = gradeService;
}
@RequestMapping("/desc")
public String desc(Model model, HttpSession session){
public String desc(Model model, HttpSession session,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
SecurityContextImpl securityContext = (SecurityContextImpl)session.getAttribute("SPRING_SECURITY_CONTEXT");
String currentStudentId = ((UserDetails) securityContext.getAuthentication().getPrincipal()).getUsername();
model.addAttribute("prefix","/desc");
if(gradeRepository.findAllByStudentID(currentStudentId)!=null){
try {
List<Grade> gradeListDesc = gradeRepository.findAllByStudentIDOrderByGradeDesc(currentStudentId);
Page<Grade> gradeListDesc = gradeService.getGradeListByStuIDDESCByGrade(pageNum,pageSize,
currentStudentId);
model.addAttribute("gradeItems", gradeListDesc);
int minGrade = gradeRepository.findMinGrade(currentStudentId);
model.addAttribute("minGrade", minGrade);
......@@ -76,12 +89,16 @@ public class GradeController {
return "page/QueryGrade";
}
@RequestMapping("/asc")
public String asc(Model model, HttpSession session){
public String asc(Model model, HttpSession session,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
SecurityContextImpl securityContext = (SecurityContextImpl)session.getAttribute("SPRING_SECURITY_CONTEXT");
String currentStudentId = ((UserDetails) securityContext.getAuthentication().getPrincipal()).getUsername();
model.addAttribute("prefix","/asc");
if(gradeRepository.findAllByStudentID(currentStudentId)!=null){
try {
List<Grade> gradeListAsc = gradeRepository.findAllByStudentIDOrderByGradeAsc(currentStudentId);
Page<Grade> gradeListAsc = gradeService.getGradeListByStuIDASCByGrade(pageNum,pageSize,
currentStudentId);
int minGrade = gradeRepository.findMinGrade(currentStudentId);
int maxGrade = gradeRepository.findMaxGrade(currentStudentId);
int sumCredit = gradeRepository.findSumCredit(currentStudentId);
......@@ -110,12 +127,15 @@ public class GradeController {
}
@RequestMapping("/toQueryGrade")
public String toQueryGrade(Model model, HttpSession session){
public String toQueryGrade(Model model, HttpSession session,
@RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
SecurityContextImpl securityContext = (SecurityContextImpl)session.getAttribute("SPRING_SECURITY_CONTEXT");
String currentStudentId = ((UserDetails) securityContext.getAuthentication().getPrincipal()).getUsername();
model.addAttribute("prefix","/toQueryGrade");
if(gradeRepository.findAllByStudentID(currentStudentId)!=null){
try {
List<Grade> gradeList = gradeRepository.findAllByStudentID(currentStudentId);
Page<Grade> gradeList = gradeService.getGradeListByStuID(pageNum,pageSize,currentStudentId);
int minGrade = gradeRepository.findMinGrade(currentStudentId);
int maxGrade = gradeRepository.findMaxGrade(currentStudentId);
int sumCredit = gradeRepository.findSumCredit(currentStudentId);
......
......@@ -9,6 +9,8 @@
package com.pyc.campus.dao;
import com.pyc.campus.domain.Grade;
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.Query;
import org.springframework.data.repository.query.Param;
......@@ -19,6 +21,13 @@ import java.util.List;
public interface GradeRepository extends JpaRepository<Grade, Long> {
List<Grade> findAllByTermAndStudentID(String term,String studentId);
List<Grade> findAllByStudentID(String studentId);
@Query("select g from Grade g where g.studentID=:stuId")
Page<Grade> getAllByStudentID(@Param("stuId") String stuID, Pageable pageable);
Page<Grade> getAllByStudentIDOrderByGradeDesc(@Param("stuId")String stuID, Pageable pageable);
Page<Grade> getAllByStudentIDOrderByGradeAsc(@Param("stuId")String stuId, Pageable pageable);
@RestResource(path="findAllByName", rel="findAllByName")
List<Grade> findAllByName(@Param("name")String name);
// 按成绩降序排列
......
......@@ -7,23 +7,34 @@
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 Grade {
public class Grade implements Serializable {
@Id
@GeneratedValue
long id;
@Column(nullable = true,unique = true)
private String term; // 学期
@Column(nullable = true,unique = true)
private String studentID; // 学号
@Column(nullable = true,unique = true)
private String name; // 学生姓名
@Column(nullable = true,unique = true)
private String courseCode; // 课程编号
@Column(nullable = true,unique = true)
private String courseName; // 课程名称
@Column(nullable = true,unique = true)
private int grade; // 课程成绩
@Column(nullable = true,unique = true)
private float gpa; // 绩点
@Column(nullable = true,unique = true)
private int learnHour; //学时
@Column(nullable = true,unique = true)
private int credit; // 学分
public Grade(){
super();
......@@ -122,4 +133,19 @@ public class Grade {
this.term = term;
}
@Override
public String toString() {
return "Grade{" +
"id=" + id +
", term='" + term + '\'' +
", studentID='" + studentID + '\'' +
", name='" + name + '\'' +
", courseCode='" + courseCode + '\'' +
", courseName='" + courseName + '\'' +
", grade=" + grade +
", gpa=" + gpa +
", learnHour=" + learnHour +
", credit=" + credit +
'}';
}
}
package com.pyc.campus.service;
import com.pyc.campus.domain.Grade;
import org.springframework.data.domain.Page;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file GradeService
* @pack com.pyc.campus.service
* @date 2021/1/29
* @time 10:34
* @E-mail 2923616405@qq.com
**/
public interface GradeService {
Page<Grade> getGradeListByStuID(int pageNum, int pageSize,String stuId);
Page<Grade> getGradeListByStuIDDESCByGrade(int pageNum, int pageSize,String stuId);
Page<Grade> getGradeListByStuIDASCByGrade(int pageNum, int pageSize,String stuId);
}
......@@ -7,6 +7,7 @@
package com.pyc.campus.service;
import com.pyc.campus.service.impl.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.SimpleMailMessage;
......@@ -14,7 +15,7 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Service
public class MailServiceImpl implements MailService{
public class MailServiceImpl implements MailService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
......
package com.pyc.campus.service.impl;
import com.pyc.campus.dao.GradeRepository;
import com.pyc.campus.domain.Grade;
import com.pyc.campus.service.GradeService;
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.domain.Sort;
import org.springframework.stereotype.Service;
/**
* @author 御承扬
* @product IntelliJ IDEA
* @project campus
* @file GradeServiceImpl
* @pack com.pyc.campus.service.impl
* @date 2021/1/29
* @time 10:39
* @E-mail 2923616405@qq.com
**/
@Service
public class GradeServiceImpl implements GradeService {
@Autowired
GradeRepository gradeRepository;
@Override
public Page<Grade> getGradeListByStuID(int pageNum, int pageSize, String stuId) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return gradeRepository.getAllByStudentID(stuId,pageable);
}
@Override
public Page<Grade> getGradeListByStuIDDESCByGrade(int pageNum, int pageSize, String stuId) {
Pageable pageable = PageRequest.of(pageNum, pageSize);
return gradeRepository.getAllByStudentIDOrderByGradeDesc(stuId,pageable);
}
@Override
public Page<Grade> getGradeListByStuIDASCByGrade(int pageNum, int pageSize, String stuId) {
Pageable pageable = PageRequest.of(pageNum,pageSize);
return gradeRepository.getAllByStudentIDOrderByGradeAsc(stuId,pageable);
}
}
......@@ -6,7 +6,7 @@
//E-mail:2923616405@qq.com
package com.pyc.campus.service;
package com.pyc.campus.service.impl;
public interface MailService {
/**
......
......@@ -10,10 +10,12 @@ spring.datasource.username=pyc
spring.datasource.password=root19537
#spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
#spring.jpa.open-in-view=true
spring.jpa.properties.hibernate.dialect = com.pyc.campus.config.MysqlConfig
logging.config=src/main/resources/logback-spring.xml
logging.level.com.pyc.campus.aspect.WebLogAspect = info
logging.level.root=info
logging.level.web=info
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent-output=true
......
......@@ -94,7 +94,7 @@
<hr class="hidden-sm hidden-md hidden-lg">
</div>
<div class="col-md-8">
<form class="form-inline" name="form" method="post" th:action="@{/queryByTerm}">
<!--<form class="form-inline" name="form" method="post" th:action="@{/queryByTerm}">
<div class="form-group">
<label for="term" class="sr-only">学年学期</label>
<div class="input-group">
......@@ -102,11 +102,12 @@
</div>
</div>
<button type="submit" class="btn btn-primary">查询</button>
</form>
</form>-->
<div class="table-box">
<table class="table table-striped">
<thead>
<tr>
<th>序号</th>
<th>学年学期</th>
<th>学号</th>
<th>姓名</th>
......@@ -120,6 +121,7 @@
</thead>
<tbody th:if="${not #lists.isEmpty(gradeItems)}">
<tr th:each="grade:${gradeItems}">
<th scope="row" th:text="${gradeStat.index + 1}">1</th>
<td th:text="${grade.term}"></td>
<td th:text="${grade.studentID}"></td>
<td th:text="${grade.name}"></td>
......@@ -132,6 +134,36 @@
</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="${gradeItems.hasPrevious()}">
<!--/*@thymesVar id="previousPageable" type="org.springframework.data.domain.Page"*/-->
<a th:href="${prefix}+'?pageNum=' + ${gradeItems.previousPageable().getPageNumber()}" th:text="上一页"></a>
</li>
<!-- 中间页 -->
<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>
</li>
<!-- 下一页 -->
<li th:if="${gradeItems.hasNext()}">
<a th:href="${prefix}+'?pageNum=' + ${gradeItems.nextPageable().getPageNumber()}" th:text="下一页"></a>
</li>
<!-- 尾页 -->
<li>
<a th:href="${prefix}+'?pageNum=' + ${gradeItems.getTotalPages() - 1}">尾页</a>
</li>
</ul>
</div>
<br>
<h3>
......@@ -153,7 +185,7 @@
</div>
</div>
</div>
</div>
<div id="scroll">
<div class="scrollItem" id="toTop">顶部</div>
<div class="scrollItem" id="toBottom">底部</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册