main
parent
3e6a5e84f4
commit
a1993d8804
@ -1,77 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<excludeFolder url="file://$MODULE_DIR$/${project.build.directory}/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/${project.build.directory}/test-classes" />
|
||||
</content>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<webroots />
|
||||
<sourceRoots>
|
||||
<root url="file://$MODULE_DIR$/src/main/java" />
|
||||
<root url="file://$MODULE_DIR$/src/main/resources" />
|
||||
</sourceRoots>
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.17.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.17.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.12.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.56" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.56" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.56" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:4.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.3.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.8.18" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,6 @@
|
||||
package com.example.common;
|
||||
|
||||
public enum RoleEnum {
|
||||
ADMIN, // 管理员
|
||||
STUDENT // 学生
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Course;
|
||||
import com.example.service.CourseService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/course")
|
||||
|
||||
public class CourseController {
|
||||
|
||||
@Resource
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "5") Integer pageSize) {
|
||||
PageInfo<Course> pageInfo = courseService.selectPage(pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.controller;
|
||||
|
||||
public class StudentController {
|
||||
}
|
||||
@ -1,58 +1,41 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Course {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String no;
|
||||
private String descr;
|
||||
private String times;
|
||||
private String teacher;
|
||||
private String courseId;
|
||||
private String title;
|
||||
private String deptName;
|
||||
private Integer credits;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
public String getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
public void setCourseId(String courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getDeptName() {
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setDeptName(String deptName) {
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public String getNo() {
|
||||
return no;
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setNo(String no) {
|
||||
this.no = no;
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescr() {
|
||||
return descr;
|
||||
}
|
||||
|
||||
public void setDescr(String descr) {
|
||||
this.descr = descr;
|
||||
}
|
||||
|
||||
public String getTimes() {
|
||||
return times;
|
||||
}
|
||||
|
||||
public void setTimes(String times) {
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
public Integer getCredits() {
|
||||
return credits;
|
||||
}
|
||||
|
||||
public void setTeacher(String teacher) {
|
||||
this.teacher = teacher;
|
||||
public void setCredits(Integer credits) {
|
||||
this.credits = credits;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Admin;
|
||||
import com.example.entity.Account;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
public interface AdminMapper {
|
||||
|
||||
@Select("select * from admin where username = #{username}")
|
||||
Admin selectByUsername(String username);
|
||||
Account selectByUsername(String username);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Course;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CourseMapper {
|
||||
|
||||
@Select("select * from course order by courseId desc")
|
||||
List<Course> selectAll();
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Student;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface StudentMapper {
|
||||
|
||||
@Select("select * from student where username = #{username}")
|
||||
Student selectByUsername(String username);
|
||||
|
||||
@Insert("insert into student (username, password, name, phone, email, sex, birth, avatar, role) " +
|
||||
"values (#{username}, #{password}, #{name}, #{phone}, #{email}, #{sex}, #{birth}, #{avatar}, #{role})")
|
||||
void insert(Student student);
|
||||
|
||||
@Delete("delete from student where id = #{id}")
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Update("update student set username = #{username}, password = #{password}, name = #{name}, phone = #{phone}, " +
|
||||
"email = #{email}, sex = #{sex}, birth = #{birth}, avatar = #{avatar} where id = #{id}")
|
||||
void updateById(Student student);
|
||||
|
||||
@Select("select * from student where username like concat('%', #{username}, '%') and name like concat('%', #{name}, '%') order by id desc")
|
||||
List<Student> selectAll(Student student);
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Student;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.StudentMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StudentService {
|
||||
|
||||
@Resource
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Account login(Account account) {
|
||||
Account dbStudent = studentMapper.selectByUsername(account.getUsername());
|
||||
if (dbStudent == null) {
|
||||
// 没有用户
|
||||
throw new CustomException("账号或密码错误");
|
||||
}
|
||||
// 比较密码
|
||||
if (!account.getPassword().equals(dbStudent.getPassword())) {
|
||||
throw new CustomException("账号或密码错误");
|
||||
}
|
||||
// 登录成功
|
||||
return dbStudent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 学生注册
|
||||
*/
|
||||
public void register(Account account) {
|
||||
Student student = new Student();
|
||||
student.setUsername(account.getUsername()); // 账号
|
||||
student.setPassword(account.getPassword()); // 密码
|
||||
this.add(student);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void add(Student student) {
|
||||
Student dbStudent = studentMapper.selectByUsername(student.getUsername());
|
||||
if (dbStudent != null) { // 已有同名账号 不允许插入
|
||||
throw new CustomException("账号已存在");
|
||||
}
|
||||
if (ObjectUtil.isEmpty(student.getName())) {
|
||||
student.setName(student.getUsername());
|
||||
}
|
||||
student.setRole(RoleEnum.STUDENT.name());
|
||||
studentMapper.insert(student);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
studentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void updateById(Student student) {
|
||||
studentMapper.updateById(student);
|
||||
}
|
||||
|
||||
public PageInfo<Student> selectPage(Integer pageNum, Integer pageSize, Student student) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Student> studentList = studentMapper.selectAll(student);
|
||||
return PageInfo.of(studentList);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
artifactId=springboot
|
||||
groupId=com.example
|
||||
version=0.0.1-SNAPSHOT
|
||||
@ -0,0 +1,13 @@
|
||||
com\example\common\Result.class
|
||||
com\example\entity\Course.class
|
||||
com\example\common\CorsConfig.class
|
||||
com\example\service\AdminService.class
|
||||
com\example\service\CourseService.class
|
||||
com\example\exception\GlobalExceptionHandler.class
|
||||
com\example\SpringbootApplication.class
|
||||
com\example\exception\CustomException.class
|
||||
com\example\mapper\CourseMapper.class
|
||||
com\example\entity\Admin.class
|
||||
com\example\controller\WebController.class
|
||||
com\example\controller\CourseController.class
|
||||
com\example\mapper\AdminMapper.class
|
||||
@ -0,0 +1,13 @@
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\mapper\CourseMapper.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\SpringbootApplication.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\common\Result.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\exception\GlobalExceptionHandler.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\common\CorsConfig.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\service\CourseService.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\exception\CustomException.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\entity\Course.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\controller\CourseController.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\entity\Admin.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\mapper\AdminMapper.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\service\AdminService.java
|
||||
C:\Users\MEI\Desktop\Demo-master\demo\springboot\src\main\java\com\example\controller\WebController.java
|
||||
Binary file not shown.
Loading…
Reference in new issue