学生管理系统demo
This commit is contained in:
commit
83bf9cad11
|
@ -0,0 +1,2 @@
|
|||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>edu.leijiaqi</groupId>
|
||||
<artifactId>HW1</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>202201080229-HW1</name>
|
||||
<description>202201080229-HW1</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter-test</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.graphql.dgs.codegen</groupId>
|
||||
<artifactId>graphql-dgs-codegen-gradle</artifactId>
|
||||
<version>6.2.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package edu.leijiaqi;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@MapperScan("edu.leijiaqi.mapper")
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package edu.leijiaqi.controller;
|
||||
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import edu.leijiaqi.service.AccountStudentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class AccountStudentController {
|
||||
|
||||
private final AccountStudentService accountStudentService;
|
||||
|
||||
@Autowired
|
||||
public AccountStudentController(AccountStudentService accountStudentService) {
|
||||
this.accountStudentService = accountStudentService;
|
||||
}
|
||||
|
||||
@PostMapping("/accountstudent")
|
||||
public String addAccountStudent(Student student, Model model){
|
||||
accountStudentService.addStudentAccount(student);
|
||||
return "redirect:/students";
|
||||
}
|
||||
@GetMapping("/deleteaccountstudent/{account}")
|
||||
public String deleteAccountStudent(@PathVariable String account, Model model){
|
||||
System.out.println(account);
|
||||
accountStudentService.deleteStudentAccount(account);
|
||||
return "redirect:/students";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package edu.leijiaqi.controller;
|
||||
|
||||
import edu.leijiaqi.service.AccountService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
private final AccountService accountService;
|
||||
@Autowired
|
||||
public LoginController(AccountService accountService) {
|
||||
this.accountService = accountService;
|
||||
}
|
||||
@GetMapping({"/", "/login"})
|
||||
public String loginPage(Model model){
|
||||
model.addAttribute("title","教务系统");
|
||||
return "login";
|
||||
}
|
||||
@PostMapping("/login")
|
||||
public String login(String username, String password, Model model){
|
||||
boolean result = accountService.validate(username, password);
|
||||
if (result){
|
||||
return "index";
|
||||
}
|
||||
return "login";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package edu.leijiaqi.controller;
|
||||
|
||||
import edu.leijiaqi.pojo.Account;
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import edu.leijiaqi.service.StudentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class StudentController {
|
||||
|
||||
private final StudentService studentService;
|
||||
@Autowired
|
||||
public StudentController(StudentService studentService) {
|
||||
this.studentService = studentService;
|
||||
}
|
||||
// 加载页面
|
||||
@GetMapping("/studentpage")
|
||||
public String getStudentPage(){
|
||||
return "student";
|
||||
}
|
||||
@GetMapping("/addstudentpage")
|
||||
public String addStudentPage(@CookieValue(value = "username",required = false)String username, Model model){
|
||||
Account account = new Account();
|
||||
account.setAccount(username);
|
||||
model.addAttribute("account",account);
|
||||
return "addstudentpage";
|
||||
}
|
||||
@PostMapping("/addstudentpage")
|
||||
public String insertStudent(Student student){
|
||||
studentService.insertStudent(student);
|
||||
return "redirect:/studentpage";
|
||||
}
|
||||
// 处理数据
|
||||
@GetMapping("/students")
|
||||
public String getAllStudents(Model model){
|
||||
List<Student> students = studentService.getAllStudents();
|
||||
model.addAttribute("students",students);
|
||||
return "student";
|
||||
}
|
||||
@GetMapping("updatestudentpage/{id}")
|
||||
public String updateStudentPage(@PathVariable String id,
|
||||
Model model){
|
||||
Student student = studentService.getStudentById(id);
|
||||
System.out.println(student);
|
||||
model.addAttribute("student",student);
|
||||
return "updatestudent";
|
||||
}
|
||||
@PostMapping("/updatestudent")
|
||||
public String updateStudent(@ModelAttribute Student student) {
|
||||
studentService.updateStudent(student);
|
||||
return "redirect:/students";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package edu.leijiaqi.mapper;
|
||||
|
||||
import edu.leijiaqi.pojo.Account;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AccountMapper {
|
||||
// 查询账号
|
||||
Account getAccount(String account);
|
||||
// 添加账号
|
||||
void insertAccount(Account account);
|
||||
|
||||
// 根据账号获取学生信息
|
||||
List<Account> getAccountWithDetails();
|
||||
|
||||
void deleteByAccount(String account);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package edu.leijiaqi.mapper;
|
||||
|
||||
import edu.leijiaqi.pojo.Score;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ScoreMapper {
|
||||
//新增成绩
|
||||
void insert(Score score);
|
||||
// 更新成绩
|
||||
void update(Score score);
|
||||
// 根据id删除成绩
|
||||
void deleteById(Integer id);
|
||||
// 批量删除成绩
|
||||
void deleteByIds(List<Integer> ids);
|
||||
// 根据no查询成绩
|
||||
List<Score> getAll();
|
||||
//List<Score> getAllWithName();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package edu.leijiaqi.mapper;
|
||||
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface StudentMapper {
|
||||
//查询所有学生信息
|
||||
List<Student> getAll();
|
||||
|
||||
//根据id查询学生
|
||||
Student getById(String id);
|
||||
|
||||
//根据姓名长度和性别查询
|
||||
List<Student> getByLength(Integer len, Integer gender);
|
||||
|
||||
// 添加学生
|
||||
void insertStudent(Student student);
|
||||
|
||||
//动态更新学生
|
||||
void update(Student student);
|
||||
|
||||
//查询学生信息(带有性别名称)
|
||||
List<Student> getAllWithGender();
|
||||
//查询学生的所有成绩
|
||||
Student getStudentScoresById(String id);
|
||||
|
||||
void deleteById(String id);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package edu.leijiaqi.mapper;
|
||||
|
||||
import edu.leijiaqi.pojo.StudentScore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface StudentScoreMapper {
|
||||
StudentScore getByNo(String id);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Account extends BaseEntity{
|
||||
private Integer id;
|
||||
private String account;
|
||||
private String password;
|
||||
private Integer role = 1;
|
||||
//一对一查询
|
||||
private Student studentDetails;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class BaseEntity {
|
||||
private Integer createBy;
|
||||
private LocalDateTime createTime;
|
||||
private Integer updateBy;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Course extends BaseEntity{
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Gender extends BaseEntity{
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Score extends BaseEntity{
|
||||
private Integer id;//流水号
|
||||
private String studentId;
|
||||
private String courseId;
|
||||
private Integer score;
|
||||
private LocalDateTime createTime;
|
||||
// 学生和课程是一的一方
|
||||
private Student student;
|
||||
private Course course;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Student extends BaseEntity{
|
||||
private String id;
|
||||
private String name;
|
||||
private String gender;
|
||||
// @DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate birthday;
|
||||
//一方放入多方(性别是一方)
|
||||
private Gender genderDetails;
|
||||
//多方放一方(成绩是多方)
|
||||
private List<Score> scores;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package edu.leijiaqi.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class StudentScore {
|
||||
private Student student;
|
||||
private List<Score> scores;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package edu.leijiaqi.service;
|
||||
|
||||
import edu.leijiaqi.pojo.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public interface AccountService {
|
||||
// 验证数据集账号密码
|
||||
@Transactional
|
||||
boolean validate(String username, String password);
|
||||
@Transactional
|
||||
void insertAccount(Account account);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package edu.leijiaqi.service;
|
||||
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public interface AccountStudentService {
|
||||
@Transactional
|
||||
void addStudentAccount(Student student);
|
||||
@Transactional
|
||||
void deleteStudentAccount(String account);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package edu.leijiaqi.service;
|
||||
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface StudentService {
|
||||
List<Student> getAllStudents();
|
||||
void insertStudent(Student student);
|
||||
Student getStudentById(String id);
|
||||
void updateStudent(Student student);
|
||||
void deleteStudent(String id);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package edu.leijiaqi.service.impl;
|
||||
|
||||
import edu.leijiaqi.mapper.AccountMapper;
|
||||
import edu.leijiaqi.pojo.Account;
|
||||
import edu.leijiaqi.service.AccountService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
|
||||
private final AccountMapper accountMapper;
|
||||
@Autowired
|
||||
public AccountServiceImpl(AccountMapper accountMapper) {
|
||||
this.accountMapper = accountMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean validate(String username, String password) {
|
||||
Account dbAccount = accountMapper.getAccount(username);
|
||||
if(dbAccount != null && dbAccount.getPassword().equals(password)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertAccount(Account account) {
|
||||
accountMapper.insertAccount(account);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package edu.leijiaqi.service.impl;
|
||||
|
||||
import edu.leijiaqi.mapper.AccountMapper;
|
||||
import edu.leijiaqi.mapper.StudentMapper;
|
||||
import edu.leijiaqi.pojo.Account;
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import edu.leijiaqi.service.AccountStudentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class AccountStudentServiceImpl implements AccountStudentService {
|
||||
private AccountMapper accountMapper;
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
public AccountStudentServiceImpl(AccountMapper accountMapper, StudentMapper studentMapper) {
|
||||
this.accountMapper = accountMapper;
|
||||
this.studentMapper = studentMapper;
|
||||
}
|
||||
@Transactional
|
||||
@Override
|
||||
public void addStudentAccount(Student student) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 在数据库中创建Account
|
||||
Account account = new Account();
|
||||
account.setAccount(student.getId());// 学号
|
||||
account.setPassword("12346"); // 默认密码
|
||||
account.setRole(1); // 默认角色
|
||||
account.setCreateBy(1);
|
||||
account.setCreateTime(now);
|
||||
accountMapper.insertAccount(account);
|
||||
// 在数据库中创建Student
|
||||
student.setCreateBy(1);
|
||||
student.setCreateTime(now);
|
||||
studentMapper.insertStudent(student);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteStudentAccount(String account) {
|
||||
// 在数据库中删除student
|
||||
studentMapper.deleteById(account);
|
||||
// 在数据库中删除account
|
||||
accountMapper.deleteByAccount(account);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package edu.leijiaqi.service.impl;
|
||||
|
||||
import edu.leijiaqi.mapper.StudentMapper;
|
||||
import edu.leijiaqi.pojo.Student;
|
||||
import edu.leijiaqi.service.StudentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StudentServiceImpl implements StudentService {
|
||||
private final StudentMapper studentMapper;
|
||||
|
||||
@Autowired
|
||||
public StudentServiceImpl(StudentMapper studentMapper) {
|
||||
this.studentMapper = studentMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Student> getAllStudents() {
|
||||
return studentMapper.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertStudent(Student student) {
|
||||
// 添加学生之前,需要先创建账号
|
||||
studentMapper.insertStudent(student);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Student getStudentById(String id) {
|
||||
Student student = studentMapper.getById(id);
|
||||
return student;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStudent(Student student) {
|
||||
student.setUpdateBy(1);
|
||||
student.setUpdateTime(LocalDateTime.now());
|
||||
studentMapper.update(student);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStudent(String id) {
|
||||
studentMapper.deleteById(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
spring.application.name=202201080229-HW1
|
||||
|
||||
#?????
|
||||
spring.devtools.restart.enabled=true
|
||||
#??????
|
||||
spring.devtools.restart.additional-paths=src/main/java
|
||||
# ???? ???????????????????
|
||||
spring.jackson.time-zone=Asia/Shanghai
|
||||
#?? cLasspath ????WEB-INF??????????(???????????????????
|
||||
spring.devtools.restart.exclude=static/**
|
||||
|
||||
# ?????
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
# ???????????????
|
||||
spring.datasource.url=jdbc:mysql://10.33.66.120:3306/mb202201080229
|
||||
# ???????????????
|
||||
spring.datasource.username=mb202201080229
|
||||
# ???????????????
|
||||
spring.datasource.password=WJNZVR129112
|
||||
# ?? mybatis ????????????
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# ?? mybatis ???????????
|
||||
mybatis.configuration.map-underscore-to-camel-case=true
|
||||
# ?? mybatis ?????????????????
|
||||
mybatis.mapper-locations=classpath*:mapper/*.xml
|
||||
# ???????Java?????????????????
|
||||
mybatis.type-aliases-package=edu.leijiaqi.pojo
|
||||
spring.transaction.annotation-proxy-target-class=true
|
||||
|
||||
server.port=8080
|
||||
server.servlet.context-path=/
|
||||
spring.thymeleaf.cache=false
|
||||
spring.thymeleaf.prefix=classpath:/templates/
|
||||
spring.thymeleaf.suffix=.html
|
||||
spring.mvc.hiddenmethod.filter.enabled=true
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="edu.leijiaqi.mapper.AccountMapper">
|
||||
|
||||
<select id="getAccount" resultType="Account">
|
||||
select id, account, password, role
|
||||
from account
|
||||
where account = #{account}
|
||||
</select>
|
||||
|
||||
<delete id="deleteByAccount">
|
||||
delete from account where account = #{account}
|
||||
</delete>
|
||||
|
||||
<insert id="insertAccount" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into account(id, account, password, role, create_by)
|
||||
values(#{id}, #{account}, #{password}, #{role}, #{createBy})
|
||||
</insert>
|
||||
|
||||
<select id="getAccountWithDetails" resultMap="AccountWithDetails">
|
||||
select a.id, a.account, s.`name`, s.gender, s.birthday
|
||||
from account as a, student as s
|
||||
where a.account = s.id
|
||||
</select>
|
||||
<resultMap id="AccountWithDetails" type="Account">
|
||||
<id column="id" property="id" />
|
||||
<result column="account" property="account" />
|
||||
<association property="studentDetails" javaType="Student">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="gender" property="gender" />
|
||||
<result column="birthday" property="birthday" />
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<!-- 添加账号-->
|
||||
<!-- <insert id="insertAccount" keyProperty="id" useGeneratedKeys="true" parameterType="Account">-->
|
||||
<!-- <!– useGeneratedKeys = true: 表示使用数据库的自增主键 –>-->
|
||||
<!-- <!– keyProperty = "属性" :将数据库的自增主键与实体类的属性进行绑定 –>-->
|
||||
<!-- insert into account(account, password, role, create_by)-->
|
||||
<!-- values(#{account}, #{password}, #{role}, #{createBy})-->
|
||||
<!-- </insert>-->
|
||||
|
||||
<!-- 一对一查询-->
|
||||
<!-- 查询学生的详细信息-->
|
||||
<!-- resultType 与数据库对应的Java对象
|
||||
resultMap 能映射到Java对象-->
|
||||
<!-- <select id="getAccount" resultMap="AccountWithDetails" resultType="edu.leijiaqi.pojo.Account">-->
|
||||
<!-- select a.id,a.account,s.name,s.gender,s.birthday-->
|
||||
<!-- from account as a,student as s-->
|
||||
<!-- where a.account = s.id-->
|
||||
<!-- </select>-->
|
||||
|
||||
<!-- id:用于映射的唯一标识符 主键
|
||||
result 用于映射其他字段
|
||||
property Java 对象的属性名
|
||||
colum:查询结果中的列名-->
|
||||
<!-- <resultMap id="AccountWithDetails" type="Account">-->
|
||||
<!-- <id column="id" property="id"/>-->
|
||||
<!-- <result column="account" property="account"/>-->
|
||||
<!-- <association property="studentDetails" javaType="Student">-->
|
||||
<!-- <id column="id" property="id"/>-->
|
||||
<!-- <result column="name" property="name"/>-->
|
||||
<!-- <result column="gender" property="gender"/>-->
|
||||
<!-- <result column="birthday" property="birthday"/>-->
|
||||
<!-- </association>-->
|
||||
<!-- </resultMap>-->
|
||||
|
||||
|
||||
<!-- <select id="getByAccount" resultType="edu.leijiaqi.pojo.Account">-->
|
||||
<!-- select account,password,role-->
|
||||
<!-- from account-->
|
||||
<!-- where account = #{account}-->
|
||||
<!-- </select>-->
|
||||
|
||||
|
||||
<!-- <select id="getAccountWithDetails" resultType="edu.leijiaqi.pojo.Account">-->
|
||||
|
||||
<!-- </select>-->
|
||||
|
||||
<!-- <delete id="deleteByAccount">-->
|
||||
|
||||
<!-- </delete>-->
|
||||
</mapper>
|
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="edu.leijiaqi.mapper.ScoreMapper">
|
||||
<!-- 插入成绩 -->
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into score(id, student_id, course_id, score, create_by, create_time)
|
||||
values(#{id}, #{studentId}, #{courseId}, #{score}, #{createBy}, #{createTime})
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="update">
|
||||
update grade
|
||||
<set>
|
||||
<if test="grade != null">grade = #{grade},</if>
|
||||
<if test="updateTime != null"> update_time = #{updateTime}</if>
|
||||
</set>
|
||||
where no = #{no}
|
||||
</update>
|
||||
|
||||
<!-- 删除一条成绩 -->
|
||||
<delete id="deleteById">
|
||||
delete from score where id = #{id}
|
||||
</delete>
|
||||
<!-- 删除多条成绩 -->
|
||||
<delete id="deleteByIds">
|
||||
delete from score where id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 查询成绩带上名称 -->
|
||||
<select id="getAll" resultMap="ScoreWithName">
|
||||
SELECT score.id, s.`name` as student_name, c.`name` as course_name, score.score
|
||||
FROM score, student as s, course as c
|
||||
WHERE s.id = score.student_id and c.id = score.course_id
|
||||
</select>
|
||||
<resultMap id="ScoreWithName" type="Score">
|
||||
<id column="id" property="id" />
|
||||
<result column="score" property="score" />
|
||||
<association property="student" javaType="Student">
|
||||
<result column="student_name" property="name" />
|
||||
</association>
|
||||
<association property="course" javaType="Course">
|
||||
<result column="course_name" property="name" />
|
||||
</association>
|
||||
</resultMap>
|
||||
<!--新增成绩-->
|
||||
<!-- <insert id="insert" keyProperty="id" useGeneratedKeys="true">-->
|
||||
<!-- insert into score(id, student_id, course_id, score, create_by, create_time)-->
|
||||
<!-- values(#{id}, #{studentId}, #{courseId}, #{score}, #{createBy}, #{createTime})-->
|
||||
<!-- </insert>-->
|
||||
<!--根据id删除成绩-->
|
||||
<!-- <delete id="deleteById">-->
|
||||
<!-- delete from score where id = #{id}-->
|
||||
<!-- </delete>-->
|
||||
<!-- 批量删除成绩-->
|
||||
<!-- collection:集合名称-->
|
||||
<!-- item:集合遍历出来的元素/项-->
|
||||
<!-- separator:每一次遍历使用的分隔符-->
|
||||
<!-- open:遍历开始前拼接的片段-->
|
||||
<!-- close:遍历结束后拼接的片段-->
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,114 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="edu.leijiaqi.mapper.StudentMapper">
|
||||
<!-- <sql>标签定义可重用的sql片段
|
||||
<include>标签:通过属性refid,指定包含sql片段-->
|
||||
|
||||
<sql id="commonSelect">
|
||||
select id,name,gender,birthday from student
|
||||
</sql>
|
||||
|
||||
<!-- resultType="" 单条记录所封装的类型-->
|
||||
<select id="getAll" resultType="Student">
|
||||
select id, name, gender, birthday from student
|
||||
<!-- <include refid="commonSelect"></include>-->
|
||||
</select>
|
||||
|
||||
<!--根据id查询-->
|
||||
<select id="getById" resultType="Student">
|
||||
<include refid="commonSelect"></include>
|
||||
<where>
|
||||
id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 查询姓名为三个字的女生-->
|
||||
<select id="getByLength" resultType="Student">
|
||||
<include refid="commonSelect"></include>
|
||||
<where>
|
||||
char_length(student.name) = 3 and gender = 2
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 条件查询-->
|
||||
<select id="getByCondition" resultType="Student">
|
||||
<include refid="commonSelect"></include>
|
||||
<where>
|
||||
<if test="len !=null">
|
||||
char_length(student.name) = #{len}
|
||||
</if>
|
||||
<if test="gender != null">
|
||||
and gender = #{gender};
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 插入学生信息 -->
|
||||
<insert id="insertStudent" parameterType="Student">
|
||||
insert into student(id, name, gender, birthday)
|
||||
values(#{id}, #{name}, #{gender}, #{birthday})
|
||||
</insert>
|
||||
|
||||
<!-- 动态更新学生信息 -->
|
||||
<update id="update">
|
||||
update student
|
||||
<set>
|
||||
<if test="name != null"> name = #{name},</if>
|
||||
<if test="gender != null"> gender = #{gender},</if>
|
||||
<if test="birthday != null"> birthday = #{birthday},</if>
|
||||
<if test="updateBy != null"> update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null"> update_time = #{updateTime}</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<!-- 查询学生信息(带有性别名称)-->
|
||||
<select id="getAllWithGender" resultType="edu.leijiaqi.pojo.Student">
|
||||
select s.id,s.name,g.id as gid,g.name as gname,s.birthday
|
||||
FROM student as s
|
||||
JOIN gender as g on g.id = s.gender
|
||||
</select>
|
||||
|
||||
<resultMap id="StudentWithGender" type="Student">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="birthday" property="birthday"/>
|
||||
<association property="genderDetails" javaType="Gender">
|
||||
<id column="gid" property="id"/>
|
||||
<result column="gname" property="name"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
<!-- 查询学生的所有成绩-->
|
||||
<select id="getStudentScoresById" resultMap="StudentWithScore">
|
||||
SELECT s.id as sid,s.name as sname,c.id as cid,c.name as cname,sc.id as scid,sc.score
|
||||
FROM score as sc,student as s,course as c
|
||||
WHERE s.id = #{id} and s.id = sc.student_id and c.id = sc.course_id
|
||||
</select>
|
||||
<resultMap id="StudentWithScore" type="Student">
|
||||
<id column="sid" property="id" />
|
||||
<result column="sname" property="name" />
|
||||
<collection property="scores" ofType="Score">
|
||||
<id column="gid" property="id" />
|
||||
<result column="score" property="score" />
|
||||
<result column="cname" property="course.name" />
|
||||
<result column="sname" property="student.name" />
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<!-- collection:集合名称-->
|
||||
<!-- item:集合遍历出来的元素/项-->
|
||||
<!-- separator:每一次遍历使用的分隔符-->
|
||||
<!-- open:遍历开始前拼接的片段-->
|
||||
<!-- close:遍历结束后拼接的片段-->
|
||||
<delete id="deleteByIds">
|
||||
delete from student where id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<!--删除学生-->
|
||||
<delete id="deleteById">
|
||||
delete from student where id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="edu.leijiaqi.mapper.StudentScoreMapper">
|
||||
|
||||
<select id="getByNo" resultMap="StudentWithScores">
|
||||
SELECT s.id as sid, s.name as sname, c.id as cid, c.name as cname, sc.id as scid, sc.score
|
||||
FROM student as s, score as sc, course as c
|
||||
where s.id = #{id} and s.id = sc.student_id and c.id = sc.course_id
|
||||
</select>
|
||||
|
||||
<resultMap id="StudentWithScores" type="StudentScore">
|
||||
<id column="sid" property="student.id"></id>
|
||||
<result column="sname" property="student.name"/>
|
||||
<collection property="scores" ofType="Score">
|
||||
<id column="scid" property="id"/>
|
||||
<id column="score" property="score" />
|
||||
<association property="course" javaType="Course">
|
||||
<id column="cid" property="id"/>
|
||||
<id column="cname" property="name"/>
|
||||
</association>
|
||||
</collection>
|
||||
</resultMap>
|
||||
</mapper>
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>教务系统</h1>
|
||||
<h2>学生管理——添加</h2>
|
||||
<a th:href="@{/students}">查询</a>
|
||||
<a th:href="@{/addstudentpage}">添加</a>
|
||||
<form th:action="@{/accountstudent}" th:method="post">
|
||||
<p>学号: <input type="text" name="id"/></p>
|
||||
<p>姓名: <input type="text" name="name" /></p>
|
||||
<p>性别: <input type="text" name="gender" /></p>
|
||||
<p>出生日期: <input type="date" name="birthday"/></p>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</body>-
|
||||
</html>
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>教务系统</h1>
|
||||
<div>
|
||||
<a th:href="@{/studentpage}">学生管理</a>
|
||||
<a th:href="@{/classpage}">课程管理</a>
|
||||
<a th:href="@{/gradepage}">成绩管理</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<!--<form th:action="@{/login}" method="post">-->
|
||||
<!-- <div><label>账号:</label><input type="text" name="account" value="admin"></div>-->
|
||||
<!-- <div><label>密码:</label><input type="password" name="password" value="admin"></div>-->
|
||||
<!-- <div><input type="submit" value="登录"></div>-->
|
||||
<!--</form>-->
|
||||
<h1 th:text="${title}"></h1>
|
||||
<h1>登陆</h1>
|
||||
<!-- 登陆注册 -->
|
||||
<form th:action="@{/login}" method="post">
|
||||
<div><label>账号: <input type="text" name="username" value="admin"/></label></div>
|
||||
<div><label>密码: <input type="password" name="password" value="admin"/></label></div>
|
||||
<div><input type="submit" value="登录"/></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>教务系统</h1>
|
||||
<h2>学生管理</h2>
|
||||
<a th:href="@{/students}">查询</a>
|
||||
<a th:href="@{/addstudentpage}">添加</a>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>出生日期</td>
|
||||
<td>删除操作</td>
|
||||
<td>更新操作</td>
|
||||
</tr>
|
||||
<tr th:each="student:${students}">
|
||||
<td th:text="${student.id}"></td>
|
||||
<td th:text="${student.name}"></td>
|
||||
<td th:text="${student.gender}"></td>
|
||||
<td th:text="${student.birthday}"></td>
|
||||
<td>
|
||||
<a th:href="@{/deleteaccountstudent/{id}(id=${student.id})}">删除</a>
|
||||
</td>
|
||||
<td >
|
||||
<a th:href="@{/updatestudentpage/{id}(id=${student.id})}">更新</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>学生管理</h1>
|
||||
<a th:href="@{students}">查询</a>
|
||||
<a th:href="@{addstudentpage}">添加</a>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>出生日期</td>
|
||||
<td>删除操作</td>
|
||||
<td>更新操作</td>
|
||||
</tr>
|
||||
<tr th:each="student:${students}">
|
||||
<td th:text="${student.id}"></td>
|
||||
<td th:text="${student.name}"></td>
|
||||
<td th:text="${student.gender}"></td>
|
||||
<td th:text="${student.birthday}"></td>
|
||||
<td><a th:href="@{deleteaccountstudent/{id}(id=${student.id})}">删除</a></td>
|
||||
<td><a th:href="@{deleteaccountstudent/{id}(id=${student.id})}">更新</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>教务系统</h1>
|
||||
<h2>学生管理——更新</h2>
|
||||
<a th:href="@{/students}">查询</a>
|
||||
<a th:href="@{/addstudentpage}">添加</a>
|
||||
<form th:action="@{/updatestudent}" th:method="post">
|
||||
<p>学号: <input type="text" name="id" th:value="${student.id}"/></p>
|
||||
<p>姓名: <input type="text" name="name" th:value="${student.name}"/></p>
|
||||
<p>性别: <input type="text" name="gender" th:value="${student.gender}"/></p>
|
||||
<p>出生日期: <input type="date" name="birthday" th:value="${student.birthday}"/></p>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
package edu.leijiaqi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue