├── result ├── 注册.png ├── 首页.png ├── 统计1.png └── 统计2.png ├── log ├── log.log.2021-05-12.0.gz └── log.log.2021-05-13.0.gz ├── src ├── main │ ├── resources │ │ ├── static │ │ │ ├── img │ │ │ │ ├── add.png │ │ │ │ ├── back.png │ │ │ │ ├── code.bmp │ │ │ │ ├── exit.png │ │ │ │ ├── logo2.png │ │ │ │ ├── search.png │ │ │ │ ├── statistic.png │ │ │ │ └── pwd-icons-new.png │ │ │ └── css │ │ │ │ └── style.css │ │ ├── templates │ │ │ ├── common │ │ │ │ ├── bottom.html │ │ │ │ ├── head.html │ │ │ │ ├── navigate.html │ │ │ │ ├── visualize.html │ │ │ │ └── page_naiv.html │ │ │ ├── error │ │ │ │ ├── 4xx.html │ │ │ │ └── 5xx.html │ │ │ ├── user │ │ │ │ ├── login.html │ │ │ │ └── regist.html │ │ │ ├── useless │ │ │ │ └── statistic.jsp │ │ │ ├── test │ │ │ │ └── test.html │ │ │ └── menu │ │ │ │ ├── update.html │ │ │ │ ├── queryByNo.html │ │ │ │ ├── add.html │ │ │ │ ├── queryByName.html │ │ │ │ ├── queryResult.html │ │ │ │ ├── show.html │ │ │ │ └── stat.html │ │ ├── application.properties │ │ ├── application.yaml │ │ └── kaptcha.xml │ └── java │ │ └── indi │ │ └── huishi │ │ └── shizuo │ │ ├── pojo │ │ ├── User.java │ │ ├── Statistics.java │ │ └── Student.java │ │ ├── ShizuoApplication.java │ │ ├── service │ │ ├── UserService.java │ │ ├── StudentService.java │ │ └── impl │ │ │ ├── UserServiceImpl.java │ │ │ ├── UserServiceImplRedis.java │ │ │ └── StudentServiceImpl.java │ │ ├── config │ │ ├── MyBatisPlusConfig.java │ │ └── AdminWebConfig.java │ │ ├── dao │ │ ├── UserDao.java │ │ └── StudentDao.java │ │ ├── util │ │ ├── CodeUtil.java │ │ └── BeanUtil.java │ │ ├── interceptor │ │ └── LoginInterceptor.java │ │ └── controller │ │ ├── KaptchaController.java │ │ ├── UserController.java │ │ └── StudentController.java └── test │ └── java │ └── indi │ └── huishi │ └── shizuo │ ├── ShizuoApplicationTests.java │ ├── util │ └── UtilTest.java │ ├── controller │ └── StudentTest.java │ └── service │ └── ServiceTest.java ├── pom.xml ├── readme.md ├── mvnw.cmd └── mvnw /result/注册.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/result/注册.png -------------------------------------------------------------------------------- /result/首页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/result/首页.png -------------------------------------------------------------------------------- /result/统计1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/result/统计1.png -------------------------------------------------------------------------------- /result/统计2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/result/统计2.png -------------------------------------------------------------------------------- /log/log.log.2021-05-12.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/log/log.log.2021-05-12.0.gz -------------------------------------------------------------------------------- /log/log.log.2021-05-13.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/log/log.log.2021-05-13.0.gz -------------------------------------------------------------------------------- /src/main/resources/static/img/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/add.png -------------------------------------------------------------------------------- /src/main/resources/static/img/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/back.png -------------------------------------------------------------------------------- /src/main/resources/static/img/code.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/code.bmp -------------------------------------------------------------------------------- /src/main/resources/static/img/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/exit.png -------------------------------------------------------------------------------- /src/main/resources/static/img/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/logo2.png -------------------------------------------------------------------------------- /src/main/resources/static/img/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/search.png -------------------------------------------------------------------------------- /src/main/resources/static/img/statistic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/statistic.png -------------------------------------------------------------------------------- /src/main/resources/static/img/pwd-icons-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsajuHuishi/StudentScoreManagementSystemSpringBoot/HEAD/src/main/resources/static/img/pwd-icons-new.png -------------------------------------------------------------------------------- /src/main/resources/templates/common/bottom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title 5 | 6 | 7 |
8 | 9 | 学生成绩管理系统.Copyright ©2021 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/pojo/User.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.pojo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @Data 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | @ToString 12 | public class User { 13 | private Integer id; 14 | private String username; 15 | private String password; 16 | private String email; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/templates/common/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/ShizuoApplication.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | @ImportResource(locations = "classpath:kaptcha.xml") 8 | @SpringBootApplication 9 | public class ShizuoApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShizuoApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service; 2 | 3 | 4 | import indi.huishi.shizuo.pojo.User; 5 | 6 | //业务 7 | public interface UserService { 8 | 9 | /** 10 | * 注册用户 11 | * 12 | * @param user 13 | */ 14 | void registerUser(User user) throws Exception; 15 | 16 | /** 17 | * 登录 18 | * @param user 19 | * @return 20 | */ 21 | User login(User user); 22 | 23 | /** 24 | * 用户名是否已经存在 25 | * @param username 26 | * @return 27 | */ 28 | boolean existsUsername(String username); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/pojo/Statistics.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.pojo; 2 | 3 | /** 4 | * @Author: Huishi 5 | * @Date: 2021/4/17 22:31 6 | */ 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | import lombok.ToString; 12 | 13 | /** 14 | * 统计 15 | * @author Huishi 16 | */ 17 | @Data 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | @ToString 21 | public class Statistics { 22 | private String className; 23 | private Double maxScore; 24 | private Double minScore; 25 | private Double avgScore; 26 | private Integer countStudent;// 学生人数 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost:3306/student_score_ssm 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | #spring.mvc.static-path-pattern=/static/** 7 | 8 | #server.error.path=/error 9 | spring.servlet.multipart.max-file-size=10MB 10 | spring.servlet.multipart.max-request-size=100MB 11 | 12 | #server.servlet.session.timeout=60m 13 | #server.undertow.accesslog.dir=/tmp 14 | #spring.mvc.servlet.path=/mvc/ 15 | 16 | #redis 17 | spring.redis.host=169.254.0.1 18 | spring.redis.port=6379 19 | spring.redis.timeout=1000 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/templates/error/4xx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 14 | 15 | 16 |
17 |

您访问的页面不存在,或者已经删除

18 |

19 |

20 | 返回首页 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/templates/error/5xx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 14 | 15 | 16 |
17 |

您访问的后台出现错误,正在抢修

18 |

19 |

20 | 返回首页 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/java/indi/huishi/shizuo/ShizuoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.core.StringRedisTemplate; 8 | import org.springframework.data.redis.core.ValueOperations; 9 | 10 | @SpringBootTest 11 | class ShizuoApplicationTests { 12 | 13 | @Autowired 14 | RedisTemplate redisTemplate; 15 | @Test 16 | void contextLoads() { 17 | 18 | } 19 | 20 | @Test 21 | void testRedis(){ 22 | ValueOperations operations = redisTemplate.opsForValue(); 23 | 24 | operations.set("hello","world"); 25 | 26 | String hello = operations.get("hello"); 27 | System.out.println(hello); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/indi/huishi/shizuo/util/UtilTest.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.util; 2 | 3 | import indi.huishi.shizuo.pojo.Statistics; 4 | import indi.huishi.shizuo.pojo.User; 5 | import indi.huishi.shizuo.service.StudentService; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.context.annotation.Bean; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @Author: Huishi 16 | * @Date: 2021/5/13 0:09 17 | */ 18 | @SpringBootTest 19 | public class UtilTest { 20 | 21 | @Test 22 | public void test() throws Exception { 23 | User user = new User(21,"Lin Vien ty","123456","asas"); 24 | Map stringObjectMap = BeanUtil.object2Map(user); 25 | System.out.println(stringObjectMap); 26 | 27 | System.out.println(stringObjectMap.get("asas"));//null 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import indi.huishi.shizuo.pojo.Statistics; 7 | import indi.huishi.shizuo.pojo.Student; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 学生成绩管理系统 Service层 13 | * @author Huishi 14 | */ 15 | 16 | public interface StudentService { 17 | 18 | /** 19 | * 分页查询 20 | * @return 21 | */ 22 | // Page show(Integer pageNo, Integer pageSize); 23 | IPage selectPage(Page page, Integer state); 24 | 25 | int add(Student student); 26 | 27 | void update(Student student); 28 | 29 | int delete(Integer id); 30 | 31 | Student queryById(String id); 32 | 33 | Student queryByNo(String no); 34 | 35 | List queryByName(String name); 36 | 37 | List statistics(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * @Author: Huishi 12 | * @Date: 2021/5/1 0:41 13 | */ 14 | //Spring boot方式 15 | @Configuration 16 | @MapperScan("indi.huishi.shizuo.dao") 17 | public class MyBatisPlusConfig { 18 | // 最新版 19 | @Bean 20 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 21 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 22 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); 23 | return interceptor; 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/pojo/Student.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.pojo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | /** 9 | * 建立stu_score表相同的字段 10 | +-----------+-------------+------+-----+---------+----------------+ 11 | | Field | Type | Null | Key | Default | Extra | 12 | +-----------+-------------+------+-----+---------+----------------+ 13 | | NAME | varchar(20) | YES | | NULL | | 14 | | score | float | YES | | NULL | | 15 | | class_name| int(11) | YES | | NULL | | 16 | | no | varchar(20) | YES | UNI | NULL | | 17 | | id | int(11) | NO | PRI | NULL | auto_increment | 18 | +-----------+-------------+------+-----+---------+----------------+ 19 | * @author AsajuHuishi 20 | * 21 | */ 22 | @Data 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | @ToString 26 | public class Student { 27 | private Integer id; 28 | private String no; 29 | private String name; 30 | private Float score; 31 | private Integer className; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.dao; 2 | 3 | import indi.huishi.shizuo.pojo.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * 用户注册+登录 11 | * @author Huishi 12 | */ 13 | @Mapper 14 | public interface UserDao { 15 | /** 16 | * 根据用户名查询该用户是否存在(注册时判断) 17 | * @param username 18 | * @return 19 | */ 20 | @Select("select * from user where username=#{username}") 21 | User queryUserByUsername(String username); 22 | 23 | /** 24 | * 根据用户和密码查询该用户是否存在(登录时判断) 25 | * @param username 26 | * @param password 27 | * @return 28 | */ 29 | @Select("select * from user where username=#{username} and password=#{password}") 30 | User queryUserByUsernameAndPassword(@Param("username") String username, @Param("password") String password); 31 | 32 | /** 33 | * 保存用户信息(注册) 34 | * @param user 35 | * @return 36 | */ 37 | @Select("insert into user(username,password,email) values(#{username}, #{password}, #{email})") 38 | void saveUser(User user); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/indi/huishi/shizuo/controller/StudentTest.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.controller; 2 | 3 | import indi.huishi.shizuo.ShizuoApplication; 4 | import indi.huishi.shizuo.pojo.Statistics; 5 | import indi.huishi.shizuo.service.StudentService; 6 | import indi.huishi.shizuo.util.BeanUtil; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * @Author: Huishi 18 | * @Date: 2021/5/13 0:34 19 | */ 20 | @SpringBootTest(classes = ShizuoApplication.class) 21 | @RunWith(SpringRunner.class) 22 | public class StudentTest { 23 | 24 | @Autowired 25 | StudentService studentService; 26 | @Test 27 | public void test() throws Exception { 28 | System.out.println(studentService); 29 | List statistics = studentService.statistics(); 30 | List> maps = BeanUtil.objectList2ListMap(statistics); 31 | System.out.println(maps); 32 | 33 | Map> map = BeanUtil.objectList2MapList(statistics, new String[]{"minScore","maxScore","avgScore","countStudent","className"}); 34 | System.out.println(map); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | druid: 4 | aop-patterns: indi.huishi.admin.* # 监控包的位置 5 | filters: stat, wall # 开启监控 防火墙 6 | filter: 7 | stat: # SQL监控 8 | slow-sql-millis: 1000 # 慢查询时长 9 | log-slow-sql: true # 慢查询日志 10 | wall: # 防火墙 11 | enabled: true 12 | config: 13 | drop-table-allow: false # 不允许删表 14 | 15 | stat-view-servlet: # 监控页面 16 | enabled: true 17 | login-username: huishi 18 | login-password: 123456 19 | reset-enable: false 20 | web-stat-filter: # 监控web路径 21 | enabled: true 22 | exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' 23 | url-pattern: /* 24 | 25 | jdbc: 26 | template: 27 | query-timeout: 3 28 | 29 | kaptcha: 30 | height: 50 31 | width: 200 32 | content: 33 | length: 4 34 | source: abcdefghjklmnopqrstuvwxyz23456789 35 | space: 2 36 | font: 37 | color: black 38 | name: Arial 39 | size: 40 40 | background-color: 41 | from: lightGray 42 | to: white 43 | border: 44 | enabled: true 45 | color: black 46 | thickness: 1 47 | 48 | logging: 49 | level: 50 | indi.huishi.shizuo.controller: info 51 | indi.huishi.shizuo.interceptor: info 52 | indi.huishi.shizuo.service: warn 53 | indi.huishi.shizuo.dao: warn 54 | file: 55 | name: E:\java_exercise\springboot_learning\shizuo\log\log.log 56 | 57 | -------------------------------------------------------------------------------- /src/main/resources/templates/common/navigate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title 5 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 | 42 |
43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/util/CodeUtil.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.util; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | /** 8 | * @Author: Huishi 9 | * @Date: 2021/5/12 0:32 10 | */ 11 | @Slf4j 12 | public class CodeUtil { 13 | /** 14 | * 将获取到的前端参数转为string类型 15 | * @param request 16 | * @param key 17 | * @return 18 | */ 19 | public static String getString(HttpServletRequest request, String key) { 20 | try { 21 | String result = request.getParameter(key); 22 | if(result != null) { 23 | result = result.trim(); 24 | } 25 | if("".equals(result)) { 26 | result = null; 27 | } 28 | return result; 29 | }catch(Exception e) { 30 | return null; 31 | } 32 | } 33 | /** 34 | * 验证码校验 35 | * @param request 36 | * @return 37 | */ 38 | public static boolean checkVerifyCode(HttpServletRequest request) { 39 | //获取生成的验证码 40 | String verifyCodeExpected = (String) request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY); 41 | log.info("获取生成的验证码:{}",verifyCodeExpected); 42 | //获取用户输入的验证码 43 | String verifyCodeActual = CodeUtil.getString(request, "code"); 44 | if(verifyCodeActual == null ||!verifyCodeActual.equalsIgnoreCase(verifyCodeExpected)) { 45 | return false; 46 | } 47 | return true; 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/config/AdminWebConfig.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.config; 2 | 3 | import indi.huishi.shizuo.interceptor.LoginInterceptor; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 6 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * @Author: Huishi 11 | * @Date: 2021/4/28 0:23 12 | */ 13 | @Configuration 14 | public class AdminWebConfig implements WebMvcConfigurer { 15 | /** 16 | * 添加静态资源文件,外部可以直接访问地址 17 | * https://www.cnblogs.com/kangkaii/p/9023751.html 18 | * @param registry 19 | */ 20 | @Override 21 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 22 | //需要配置1:----------- 需要告知系统,这是要被当成静态文件的! 23 | //第一个方法设置访问路径前缀,第二个方法设置资源路径 24 | registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); 25 | } 26 | /** 27 | * 拦截所有请求,只放行负责登录的两个请求路径 28 | * /** 拦截所有,包括静态资源也会被拦截 29 | * /* 不包括静态资源的所有路径 30 | * @param registry 31 | */ 32 | @Override 33 | public void addInterceptors(InterceptorRegistry registry) { 34 | registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/user/**","/kaptcha/**","/static/**"); //放行的请求 35 | // registry.addInterceptor(new TestInterceptor2()).addPathPatterns("/**").excludePathPatterns("/","/login","/static/**"); //放行的请求 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/indi/huishi/shizuo/service/ServiceTest.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.google.code.kaptcha.impl.DefaultKaptcha; 6 | import indi.huishi.shizuo.dao.StudentDao; 7 | import indi.huishi.shizuo.pojo.Statistics; 8 | import indi.huishi.shizuo.pojo.Student; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @Author: Huishi 17 | * @Date: 2021/5/10 23:50 18 | */ 19 | @SpringBootTest 20 | public class ServiceTest { 21 | 22 | @Autowired 23 | StudentDao studentDao; 24 | @Test 25 | public void test1(){ 26 | // System.out.println(studentDao); 27 | List list = studentDao.getStatistics(); 28 | System.out.println(list); 29 | 30 | Page studentPage = new Page<>(2, 8); 31 | IPage page = studentDao.selectPageVo(studentPage, null); 32 | 33 | List records = page.getRecords(); 34 | System.out.println(records.size()); 35 | } 36 | 37 | @Autowired 38 | StudentService studentService; 39 | @Test 40 | public void test2(){ 41 | System.out.println(studentService); 42 | } 43 | 44 | 45 | @Autowired 46 | private DefaultKaptcha kaptcha; 47 | 48 | @Test 49 | public void test(){ 50 | String text = kaptcha.createText(); 51 | System.out.println(text); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service.impl; 2 | 3 | 4 | import indi.huishi.shizuo.dao.UserDao; 5 | import indi.huishi.shizuo.pojo.User; 6 | import indi.huishi.shizuo.service.UserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | /** 12 | * 实现用户的注册和登陆功能 13 | * @author Huishi 14 | */ 15 | @Service("userService") 16 | @Transactional(rollbackFor = Exception.class) 17 | public class UserServiceImpl implements UserService { 18 | @Autowired 19 | private UserDao userDao; 20 | 21 | /** 22 | * 注册 23 | * @param user 24 | */ 25 | @Override 26 | @Transactional(rollbackFor = Exception.class) 27 | public void registerUser (User user) throws RuntimeException{ 28 | userDao.saveUser(user); 29 | System.out.println("wait...");// 用来测试事务 30 | // System.out.println("test before exception"); 31 | // int a = 10 / 0; 32 | // System.out.println("s"); 33 | } 34 | 35 | /** 36 | * 登录 37 | * @param user 38 | * @return 39 | */ 40 | @Override 41 | @Transactional(rollbackFor = Exception.class) 42 | public User login(User user) { 43 | //判断用户名和密码是否在数据库中 44 | User user1 = userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword()); 45 | return user1; 46 | } 47 | 48 | /** 49 | * 判断用户名是否已经存在 50 | * @param username 51 | * @return返回true表示用户名已经存在 52 | */ 53 | @Override 54 | @Transactional(rollbackFor = Exception.class) 55 | public boolean existsUsername(String username) { 56 | //根据用户名查询 57 | return userDao.queryUserByUsername(username)!=null?true:false; 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/interceptor/LoginInterceptor.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.interceptor; 2 | 3 | /** 4 | * @Author: Huishi 5 | * @Date: 2021/4/28 0:17 6 | */ 7 | 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.web.servlet.HandlerInterceptor; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import javax.servlet.http.HttpSession; 15 | 16 | /** 17 | * 登录检查 18 | * 1.配置拦截器 19 | * 2.把配置放在容器中 20 | */ 21 | @Slf4j 22 | public class LoginInterceptor implements HandlerInterceptor { 23 | /** 24 | * 方法执行前 25 | * @param request 26 | * @param response 27 | * @param handler 28 | * @return 29 | * @throws Exception 30 | */ 31 | @Override 32 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 33 | HttpSession session = request.getSession(); 34 | log.info("1preHandle: {}", request.getRequestURI()); 35 | if (session.getAttribute("user") == null){ 36 | log.info("未登录"); 37 | request.setAttribute("msg","请先登录!"); 38 | request.getRequestDispatcher("/user/login").forward(request, response); 39 | return false; 40 | }else{ 41 | return true;//放行 42 | } 43 | } 44 | /** 45 | * 方法执行后 46 | */ 47 | @Override 48 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 49 | log.info("1postHandle: {}", request.getRequestURI()); 50 | } 51 | /** 52 | * 页面渲染后 53 | */ 54 | @Override 55 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 56 | log.info("1afterCompletion: {}", request.getRequestURI()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录页面 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 | 56 | 57 |
58 | 59 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/controller/KaptchaController.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.controller; 2 | 3 | /** 4 | * @Author: Huishi 5 | * @Date: 2021/4/20 22:18 6 | */ 7 | 8 | import com.google.code.kaptcha.Constants; 9 | import com.google.code.kaptcha.Producer; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | 15 | import javax.imageio.ImageIO; 16 | import javax.servlet.ServletOutputStream; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import javax.servlet.http.HttpSession; 20 | import java.awt.image.BufferedImage; 21 | 22 | /** 23 | * 验证码 24 | * https://www.jianshu.com/p/1f2f7c47e812 25 | */ 26 | @Slf4j 27 | @Controller 28 | @RequestMapping("/kaptcha") 29 | public class KaptchaController { 30 | @Autowired 31 | private Producer captchaProducer = null; 32 | @RequestMapping("/render") 33 | public void getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception { 34 | HttpSession session = request.getSession(); 35 | response.setDateHeader("Expires", 0); 36 | response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 37 | response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 38 | response.setHeader("Pragma", "no-cache"); 39 | response.setContentType("image/jpeg"); 40 | //生成验证码 41 | String capText = captchaProducer.createText(); 42 | session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText); 43 | //向客户端写出 44 | BufferedImage bi = captchaProducer.createImage(capText); 45 | ServletOutputStream out = response.getOutputStream(); 46 | ImageIO.write(bi, "jpg", out); 47 | try { 48 | out.flush(); 49 | } finally { 50 | out.close(); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/resources/kaptcha.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | yes 13 | 105,179,90 14 | blue 15 | 100 16 | 50 17 | 27 18 | code 19 | 4 20 | 宋体,楷体,微软雅黑 21 | 0123456789ABCEFGHIJKLMNOPQRSTUVWXYZ 22 | com.google.code.kaptcha.impl.WaterRipple 23 | black 24 | com.google.code.kaptcha.impl.DefaultNoise 25 | 185,56,213 26 | white 27 | 3 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/util/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.util; 2 | 3 | import indi.huishi.shizuo.pojo.Statistics; 4 | 5 | import java.lang.reflect.Field; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * @Author: Huishi 13 | * @Date: 2021/5/12 23:44 14 | */ 15 | 16 | /** 17 | * 基于反射,将obj转为map 18 | */ 19 | public class BeanUtil { 20 | /** 21 | * Pojo -> Map 22 | * @param obj 23 | * @return 24 | * @throws Exception 25 | */ 26 | public static Map object2Map(Object obj) throws Exception{ 27 | Map map = new HashMap(); 28 | Field[] fields = obj.getClass().getDeclaredFields(); 29 | for(Field field:fields){ 30 | field.setAccessible(true); 31 | map.put(field.getName(), field.get(obj)); 32 | } 33 | return map; 34 | } 35 | 36 | /** 37 | * List --> List> 38 | * @param objectList 39 | * @param 40 | * @return 41 | * @throws Exception 42 | */ 43 | public static List> objectList2ListMap(List objectList) throws Exception { 44 | ArrayList> resultList = new ArrayList<>(); 45 | Map map = new HashMap<>(); 46 | for (T t : objectList) { 47 | resultList.add(object2Map(t)); 48 | } 49 | return resultList; 50 | } 51 | 52 | /** 53 | * List --> Map> 54 | * @param objectList 55 | * @param keyName 56 | * @param 57 | * @return 58 | * @throws Exception 59 | */ 60 | public static Map> objectList2MapList(List objectList, String[] keyName) throws Exception{ 61 | Map> resultMap = new HashMap<>(); 62 | for(int i = 0; i < keyName.length; i++){ 63 | List arrayList = new ArrayList<>(); 64 | for (T t: objectList){// List有序,所以对每个对象依次变为map,然后得到对应的值,存入arrayList 65 | arrayList.add(object2Map(t).get(keyName[i])); 66 | } 67 | resultMap.put(keyName[i], arrayList);//将keyName和对应List集合存入resultMap 68 | } 69 | return resultMap; 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/service/impl/UserServiceImplRedis.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service.impl; 2 | 3 | import indi.huishi.shizuo.dao.UserDao; 4 | import indi.huishi.shizuo.pojo.User; 5 | import indi.huishi.shizuo.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.data.redis.core.SetOperations; 9 | import org.springframework.data.redis.core.StringRedisTemplate; 10 | import org.springframework.data.redis.core.ValueOperations; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import java.util.Objects; 15 | import java.util.Set; 16 | 17 | /** 18 | * @Author: Huishi 19 | * @Date: 2021/5/13 22:06 20 | */ 21 | @Service("userServiceRedis") 22 | @Transactional(rollbackFor = Exception.class) 23 | public class UserServiceImplRedis implements UserService { 24 | 25 | @Autowired 26 | StringRedisTemplate redisTemplate; 27 | 28 | @Autowired 29 | UserDao userDao; 30 | /** 31 | * 登录 32 | * @param user 33 | * @throws Exception 34 | */ 35 | @Override 36 | public User login(User user) { 37 | String username = user.getUsername(); 38 | // 判断jedis中键值对中保存的密码,是否等于输入的密码 39 | ValueOperations redisUtil = redisTemplate.opsForValue(); 40 | // 输入用户根本不存在 41 | return Objects.equals(redisUtil.get(username), user.getPassword()) ? user: null; 42 | } 43 | 44 | /** 45 | * 注册 46 | * @param user 47 | */ 48 | @Override 49 | public void registerUser(User user) { 50 | // 保存到数据库一份完整的用户注册信息,包括邮箱 51 | userDao.saveUser(user); 52 | ValueOperations opsForValue = redisTemplate.opsForValue(); 53 | SetOperations opsForSet = redisTemplate.opsForSet(); 54 | // 保存到redis用户名密码键值对 55 | try { 56 | opsForValue.set(user.getUsername(), user.getPassword()); 57 | }catch (Exception e){ 58 | throw new RuntimeException("redis发生错误"); 59 | } 60 | // 保存到redis用户名到 set 防止重复 61 | opsForSet.add("uname", user.getUsername()); 62 | } 63 | 64 | /** 65 | * Redis判断 用户名不能重复 66 | * @param username 67 | * @return 68 | */ 69 | @Override 70 | public boolean existsUsername(String username) { 71 | SetOperations opsForSet = redisTemplate.opsForSet(); 72 | return opsForSet.isMember("uname", username); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/resources/templates/useless/statistic.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%--使用JSTL遍历对象--%> 3 | 4 | 5 | 6 | 首页 7 | 8 | 9 | 36 | 37 | 42 | 43 | 44 | 54 |
55 | 当前页面:按班级统计(按成绩降序) 56 |
57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | <%-- ${map}--%> 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
班级最高分最低分平均分班级总人数
${map['className']}${map['max(score)']}${map['min(score)']}${map['round(avg(score),4)']}${map['count(*)']}
77 |
78 |
79 | 80 |
81 | 82 | AsajuHuishi 2021 83 | 84 |
85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/main/resources/templates/common/visualize.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ECharts 7 | 8 | 9 | 10 |
11 |
12 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/service/impl/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import indi.huishi.shizuo.dao.StudentDao; 6 | import indi.huishi.shizuo.pojo.Statistics; 7 | import indi.huishi.shizuo.pojo.Student; 8 | import indi.huishi.shizuo.service.StudentService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @Author: Huishi 17 | * @Date: 2021/4/17 22:57 18 | */ 19 | @Service("studentService") 20 | @Transactional(rollbackFor = Exception.class) 21 | public class StudentServiceImpl implements StudentService { 22 | 23 | @Autowired 24 | private StudentDao studentDao; 25 | // /** 26 | // * 分页显示当前页的学生信息 27 | // * @param pageNo 当前页数 28 | // * @param pageSize 每页显示信息 29 | // * @return 当前页 30 | // */ 31 | // @Override 32 | // @Transactional(rollbackFor = Exception.class) 33 | // public Page show(Integer pageNo, Integer pageSize){ 34 | // // 生成一个Page对象 35 | // Integer pageTotalCount = studentDao.getTotalCount(); 36 | // Integer begin = (pageNo - 1) * pageSize; 37 | // List list = studentDao.showAll(begin, pageSize); 38 | // Integer pageTotal; 39 | // if (pageTotalCount % pageSize == 0){ 40 | // pageTotal = pageTotalCount / pageSize; 41 | // } else{ 42 | // pageTotal = pageTotalCount / pageSize + 1; 43 | // } 44 | // 45 | // Page page = new Page(); 46 | // page.setPageTotal(pageTotal); 47 | // page.setPageNo(pageNo); 48 | // page.setItems(list); 49 | // page.setPageTotalCount(pageTotalCount); 50 | // return page; 51 | // } 52 | @Override 53 | @Transactional(rollbackFor = Exception.class) 54 | public IPage selectPage(Page page, Integer state){ 55 | return studentDao.selectPageVo(page, state); 56 | } 57 | 58 | @Override 59 | @Transactional(rollbackFor = Exception.class) 60 | public int add(Student student){ 61 | return studentDao.addStudent(student); 62 | } 63 | 64 | @Override 65 | @Transactional(rollbackFor = Exception.class) 66 | public void update(Student student){ 67 | studentDao.updateStudent(student); 68 | } 69 | 70 | @Override 71 | @Transactional(rollbackFor = Exception.class) 72 | public int delete(Integer id){ 73 | return studentDao.deleteStudent(id); 74 | } 75 | 76 | @Override 77 | @Transactional(rollbackFor = Exception.class) 78 | public Student queryByNo(String no){ 79 | return studentDao.queryByNo(no); 80 | } 81 | 82 | @Override 83 | @Transactional(rollbackFor = Exception.class) 84 | public Student queryById(String id){ 85 | return studentDao.queryById(id); 86 | } 87 | 88 | @Override 89 | @Transactional(rollbackFor = Exception.class) 90 | public List queryByName(String name){ 91 | return studentDao.queryByName(name); 92 | } 93 | 94 | @Override 95 | @Transactional(rollbackFor = Exception.class) 96 | public List statistics(){ 97 | return studentDao.getStatistics(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/dao/StudentDao.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.dao; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import indi.huishi.shizuo.pojo.Statistics; 7 | import indi.huishi.shizuo.pojo.Student; 8 | import org.apache.ibatis.annotations.*; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * 学生成绩管理系统 数据访问层 15 | * @author Huishi 16 | */ 17 | @Mapper 18 | public interface StudentDao{ 19 | 20 | // /** 21 | // * 显示全部信息:分页查询 22 | // * 23 | // * @return 24 | // */ 25 | // @Select("select * from student_score order by class_name, no limit #{begin},#{pageSize}") 26 | // @ResultMap("studentMap") 27 | // List showAll(@Param("begin") Integer begin, @Param("pageSize") Integer pageSize); 28 | 29 | /** 30 | * 增加学生记录 31 | * 32 | * @param student 33 | * @return 34 | */ 35 | @Insert("insert into student_score (no, name, score, class_name) values(#{no},#{name},#{score},#{className})") 36 | int addStudent(Student student) ; 37 | 38 | /** 39 | * 修改学生记录 40 | * 41 | * @param student 42 | * @return 43 | */ 44 | @Select("update student_score set no=#{no}, name=#{name}, score=#{score}, class_name=#{className} where id=#{id}") 45 | void updateStudent(Student student); 46 | 47 | /** 48 | * 按id删除学生记录 49 | * 50 | * @param id 51 | * @return 52 | */ 53 | @Delete("delete from student_score where id=#{id}") 54 | int deleteStudent(Integer id); 55 | 56 | /** 57 | * 根据学生id查询 58 | * 59 | * @param id 60 | * @return 61 | */ 62 | @Select("select * from student_score where id=#{id}") 63 | @Results(id = "studentMap", value = { 64 | @Result(column = "class_name", property = "className") 65 | }) 66 | Student queryById(String id); 67 | 68 | /** 69 | * 根据学生学号查询 70 | * 71 | * @param no 72 | * @return 73 | */ 74 | @Select("select * from student_score where no=#{no}") 75 | @ResultMap("studentMap") 76 | Student queryByNo(String no); 77 | 78 | /** 79 | * 根据学生姓名查询,考虑重名情况,返回List集合 80 | * 81 | * @param name 82 | * @return 83 | */ 84 | @Select("select * from student_score where name=#{name}") 85 | @ResultMap("studentMap") 86 | List queryByName(String name); 87 | 88 | 89 | /** 90 | * 统计(分班级统计学生数量,最高分,最低分,平均值)... 91 | * 92 | * @return 93 | */ 94 | @Select("select class_name as className, count(*) as countStudent, max(score) as maxScore, min(score) as minScore, round(avg(score),4) as avgScore from student_score group by class_name order by class_name") 95 | List getStatistics(); 96 | 97 | // /** 98 | // * 查询结果行数,用于分页 99 | // * @return 100 | // */ 101 | // @Select("select count(*) as totalCount from student_score") 102 | // @Results(id = "totalCount",value = { 103 | // @Result(column = "totalCount",property = "java.lang.Integer") 104 | // }) 105 | // Integer getTotalCount(); 106 | 107 | /** 108 | * 分页查询 109 | * @param page 110 | * @param state 111 | * @return 112 | */ 113 | @Select("select * from student_score") 114 | @ResultMap("studentMap") 115 | IPage selectPageVo(Page page, Integer state); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /src/main/resources/templates/test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 首页 7 | 8 | 29 | 30 | 51 | 52 | 53 | 63 |
64 | 当前页面:修改学生信息 65 |
66 | 67 | 68 | 71 | 72 | 73 | 76 | 77 | 78 | 81 | 82 | 83 | 86 | 87 | 88 | 91 | 92 | <%--隐藏域id不变,不可修改--%> 93 |
69 | 班级 70 |
74 | 学号 75 |
79 | 姓名 80 |
84 | 成绩 85 |
89 | 90 |
94 | 95 |
96 | 97 |
98 | 99 | 100 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/update.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 |
7 | 8 | 9 | 30 | 31 | 52 | 53 | 54 | 64 |
65 | 当前页面:修改学生信息 66 |
67 | 68 | 69 | 72 | 73 | 74 | 77 | 78 | 79 | 82 | 83 | 84 | 87 | 88 | 89 | 92 | 93 | 94 |
70 | 班级 71 |
75 | 学号 76 |
80 | 姓名 81 |
85 | 成绩 86 |
90 | 91 |
95 | 96 |
97 | 98 |
99 | 100 |
101 | 102 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/queryByNo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 查询 6 |
7 | 8 | 9 | 35 | 36 | 63 | 64 | 65 | 72 | 73 |
74 | 当前页面:按学号查询学生信息:[[${status}]] 75 | 76 |
77 | 78 | 79 | 82 | 83 | 84 | 89 | 90 | 91 | 94 | 95 | 96 | 99 | 100 |
80 | 81 |
85 | 要查询的学号
86 |
87 | 88 |
92 | 93 |
97 | 98 |
101 |
102 | 103 |
104 | 105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 添加 6 |
7 | 8 | 9 | 30 | 31 | 62 | 63 | 64 | 71 |
72 | 当前页面:按学号查询学生信息:[[${status}]] 73 |
74 | 75 | 76 | 81 | 82 | 83 | 86 | 87 | 88 | 91 | 92 | 93 | 96 | 97 | 98 | 101 | 102 |
77 |
78 | 该学号已被使用!
79 | 学号 80 |
84 | 姓名 85 |
89 | 成绩 90 |
94 | 班级 95 |
99 | 100 |
103 | 104 |
105 | 106 |
107 |
108 | 109 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/queryByName.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 查询 6 |
7 | 8 | 9 | 35 | 36 | 64 | 65 | 66 | 74 | 75 |
76 | 当前页面:按学号查询学生信息:[[${status}]] 77 | 78 |
79 | 80 | 81 | 84 | 85 | 86 | 91 | 92 | 93 | 96 | 97 | 98 | 101 | 102 |
82 | 83 |
87 | 要查询的学生姓名
88 |
89 | 90 |
94 | 95 |
99 | 100 |
103 |
104 | 105 |
106 | 107 |
108 | 109 | 110 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.5 9 | 10 | 11 | indi.huishi 12 | shizuo 13 | 0.0.1-SNAPSHOT 14 | shizuo 15 | Demo project for Spring Boot 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-jdbc 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-devtools 31 | runtime 32 | true 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-configuration-processor 37 | true 38 | 39 | 40 | org.projectlombok 41 | lombok 42 | true 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | com.baomidou 52 | mybatis-plus-boot-starter 53 | 3.4.1 54 | 55 | 56 | 57 | junit 58 | junit 59 | 60 | 61 | 62 | mysql 63 | mysql-connector-java 64 | runtime 65 | 66 | 67 | 68 | com.alibaba 69 | druid-spring-boot-starter 70 | 1.1.17 71 | 72 | 73 | 74 | com.github.penggle 75 | kaptcha 76 | 2.3.2 77 | 78 | 79 | 80 | org.springframework.boot 81 | spring-boot-starter-thymeleaf 82 | 83 | 84 | 85 | commons-beanutils 86 | commons-beanutils 87 | 1.7.0 88 | 89 | 90 | 91 | org.springframework.boot 92 | spring-boot-starter-data-redis 93 | 94 | 95 | 96 | redis.clients 97 | jedis 98 | 99 | 100 | 101 | 102 | 103 | 104 | org.springframework.boot 105 | spring-boot-maven-plugin 106 | 107 | 108 | 109 | org.projectlombok 110 | lombok 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/regist.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注册页面 6 | 7 |
8 | 9 | 83 | 89 | 90 | 91 |
92 | 93 |
94 | 95 | 145 | 146 |
147 | 148 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/queryResult.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 |
7 | 8 | 9 | 20 | 21 | 74 | 75 | 76 | 83 |
84 | 当前页面:按学号查询学生信息:[[${status}]] 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 106 | 107 |
班级学号姓名成绩操作
103 |     104 | 105 |
108 | 109 |
110 |
111 | 112 |
113 |
114 | 115 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.controller; 2 | 3 | 4 | import indi.huishi.shizuo.pojo.User; 5 | import indi.huishi.shizuo.service.UserService; 6 | import indi.huishi.shizuo.util.CodeUtil; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.servlet.ModelAndView; 16 | 17 | import javax.annotation.Resource; 18 | import javax.servlet.http.HttpServletRequest; 19 | import javax.servlet.http.HttpSession; 20 | 21 | 22 | /** 23 | * @Author: Huishi 24 | * @Date: 2021/4/20 17:16 25 | */ 26 | @Controller 27 | @Slf4j 28 | @RequestMapping("/user") 29 | public class UserController { 30 | 31 | @Resource(name = "userServiceRedis") 32 | private UserService userService; 33 | 34 | /** 35 | * 来到登录页 36 | * @return 37 | */ 38 | @GetMapping(value = {"/","/login"}) 39 | public String loginPage(){ 40 | return "user/login"; 41 | } 42 | 43 | /** 44 | * 验证登录信息 45 | * @param model 46 | * @param user 47 | * @param session 48 | * @return 49 | */ 50 | @PostMapping("/login.action") 51 | public String login(Model model, User user, HttpSession session) { 52 | //检查 用户名和密码是否存在 53 | User user1 = userService.login(user); 54 | if (user1 == null) { 55 | log.info("用户不存在,返回登录界面"); 56 | model.addAttribute("msg", "用户名或密码错误"); 57 | model.addAttribute("username", user.getUsername());//这里是输入的user,因为user1==null 58 | // 把错误信息 和回显表单信息 保存 59 | //返回登录界面 60 | return "user/login"; 61 | } else { 62 | log.info("跳转到显示页面"); 63 | // 保存用户成功登陆的信息在session域 因为后面都会用到 64 | session.setAttribute("user", user1); 65 | log.info("登录成功"); 66 | // ModelAndView view = new ModelAndView("redirect:/student/show.action?pageNo=1"); 67 | return "redirect:/student/show.action?pageNo=1"; 68 | } 69 | } 70 | 71 | /** 72 | * 注册 73 | */ 74 | @PostMapping("/register.action") 75 | public String register(Model model, HttpServletRequest req, HttpSession session) throws Exception { 76 | // 验证码校驗 77 | boolean checkVerifyCode = CodeUtil.checkVerifyCode(req); 78 | 79 | //1.获取请求的参数 80 | String username = req.getParameter("username"); 81 | String password = req.getParameter("password"); 82 | String email = req.getParameter("email"); 83 | String code = req.getParameter("code"); 84 | log.info("注册信息{}...", username+password+email+code); 85 | //判断验证码 忽略大小写 86 | if (checkVerifyCode) { 87 | //如果验证码正确 检查用户名是否可用 88 | if (userService.existsUsername(username)) { 89 | //如果用户名已经存在,返回注册页面 90 | // 回显 91 | model.addAttribute("msgs", "用户名已经存在"); 92 | model.addAttribute("username", username); 93 | model.addAttribute("email", email); 94 | return "user/regist"; 95 | } else { 96 | // 用户名不存在,将用户名 密码 邮箱 保存到数据库 97 | User user = new User(null, username, password, email); 98 | userService.registerUser(user); 99 | // 保存用户成功登陆的信息在session域 因为后面都会用到 100 | session.setAttribute("user", user); 101 | //跳转到 注册成功界面 102 | //跳转到显示页面 103 | // 保存用户成功登陆的信息在session域 因为后面都会用到 104 | log.info("用户{}注册成功", user); 105 | return "redirect:/student/show.action?pageNo=1"; 106 | } 107 | }else { 108 | //验证码错误 109 | log.info("验证码错误:{}", code); 110 | // 把回显信息保存到request域 回显用户名邮箱 111 | model.addAttribute("msgs","验证码错误"); 112 | model.addAttribute("username",username); 113 | model.addAttribute("email",email); 114 | return "user/regist"; 115 | } 116 | } 117 | 118 | /** 119 | * 注销 120 | * @param session 121 | */ 122 | @RequestMapping("/logout.action") 123 | protected String logout(HttpSession session){ 124 | //1.销毁Session中用户登录的信息 125 | session.invalidate(); 126 | //2.重定向到首页 127 | return "redirect:/user/login";//全路径 128 | } 129 | 130 | /** 131 | * 跳转到指定页面 132 | * @param model 133 | * @param sourceName 134 | * @return 135 | */ 136 | @GetMapping("{sourceName}.html") 137 | public String jumpTo(Model model, @PathVariable("sourceName") String sourceName){ 138 | String string = new StringBuffer().append("user/").append(sourceName).append(".html").toString(); 139 | return string; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/resources/static/css/style.css: -------------------------------------------------------------------------------- 1 | @CHARSET "UTF-8"; 2 | 3 | * { 4 | margin: 0; 5 | font-family:"Microsoft Yahei"; 6 | color: #666; 7 | } 8 | 9 | div{ 10 | margin: auto; 11 | margin-bottom: 10px; 12 | margin-top: 10px; 13 | 14 | } 15 | 16 | #header { 17 | height: 82px; 18 | width: 1200px; 19 | } 20 | 21 | #main { 22 | height: 550px; 23 | width: 1200px; 24 | border: 1px black solid; 25 | overflow: auto; 26 | } 27 | #main_description { 28 | color: blue; 29 | font-size: medium; 30 | font-family: 黑体; 31 | } 32 | 33 | #bottom { 34 | height: 30px; 35 | width: 1200px; 36 | text-align: center; 37 | } 38 | 39 | #book{ 40 | width: 100%; 41 | height: 90%; 42 | margin: auto; 43 | 44 | } 45 | 46 | .b_list{ 47 | height:300px; 48 | width:250px; 49 | margin: 20px; 50 | float: left; 51 | margin-top:0px; 52 | margin-bottom:0px; 53 | border: 1px #e3e3e3 solid; 54 | } 55 | 56 | #page_nav{ 57 | width: 100%; 58 | height: 10px; 59 | margin: auto; 60 | 61 | text-align: center; 62 | } 63 | 64 | #pn_input { 65 | width: 30px; 66 | text-align: center; 67 | } 68 | 69 | .img_div{ 70 | height: 150px; 71 | text-align: center; 72 | } 73 | 74 | .book_img { 75 | height:150px; 76 | width:150px; 77 | } 78 | 79 | .book_info { 80 | 81 | text-align: center; 82 | } 83 | 84 | .book_info div{ 85 | height: 10px; 86 | width: 300px; 87 | text-align: left; 88 | } 89 | 90 | .wel_word{ 91 | font-size: 30px; 92 | float: left; 93 | margin-top: 30px; 94 | } 95 | 96 | .logo_img{ 97 | float: left; 98 | } 99 | 100 | 101 | #header div a { 102 | text-decoration: none; 103 | font-size: 20px; 104 | font-family: 黑体; 105 | } 106 | 107 | #header div{ 108 | float: right; 109 | margin-top: 55px; 110 | } 111 | 112 | .book_cond{ 113 | margin-left: 500px; 114 | } 115 | 116 | .book_cond input{ 117 | width: 50px; 118 | text-align: center; 119 | } 120 | 121 | /*登录页面CSS样式 */ 122 | 123 | #login_header{ 124 | height: 82px; 125 | width: 1200px; 126 | } 127 | 128 | .login_banner{ 129 | height:475px; 130 | background-color: #C39987; 131 | } 132 | 133 | .login_form{ 134 | height:310px; 135 | width:406px; 136 | float: right; 137 | margin-right:50px; 138 | margin-top: 50px; 139 | background-color: #fff; 140 | } 141 | 142 | #content { 143 | height: 475px; 144 | width: 1200px; 145 | } 146 | 147 | .login_box{ 148 | margin: 20px; 149 | height: 260px; 150 | width: 366px; 151 | } 152 | 153 | h1 { 154 | font-size: 20px; 155 | } 156 | .msg_cont{ 157 | background: none repeat scroll 0 0 #fff6d2; 158 | border: 1px solid #ffe57d; 159 | color: #666; 160 | height: 18px; 161 | line-height: 18px; 162 | padding: 3px 10px 3px 40px; 163 | position: relative; 164 | border: none; 165 | } 166 | 167 | .msg_cont b { 168 | background: url("../img/pwd-icons-new.png") no-repeat scroll -104px -22px rgba(0, 0, 0, 0); 169 | display: block; 170 | height: 17px; 171 | left: 10px; 172 | margin-top: -8px; 173 | overflow: hidden; 174 | position: absolute; 175 | top: 50%; 176 | width: 16px; 177 | } 178 | 179 | .form .itxt { 180 | border: 0 none; 181 | float: none; 182 | font-family: "宋体"; 183 | font-size: 14px; 184 | height: 18px; 185 | line-height: 18px; 186 | overflow: hidden; 187 | padding: 10px 0 10px 10px; 188 | width: 220px; 189 | border: 1px #e3e3e3 solid; 190 | } 191 | 192 | #btnSubmit{ 193 | color: red; 194 | font-family: 黑体; 195 | font-size: medium; 196 | } 197 | 198 | #sub_btn{ 199 | background-color: #C39987; 200 | border: none; 201 | color: #fff; 202 | width: 360px; 203 | height: 40px; 204 | } 205 | 206 | #l_content { 207 | float: left; 208 | margin-top: 150px; 209 | margin-left: 300px; 210 | } 211 | 212 | #l_content span { 213 | font-size: 60px; 214 | color: white; 215 | } 216 | 217 | .tit h1 { 218 | float: left; 219 | margin-top: 5px; 220 | } 221 | 222 | .tit a { 223 | float: right; 224 | margin-left: 10px; 225 | margin-top: 10px; 226 | color: red; 227 | text-decoration: none; 228 | } 229 | 230 | .tit .errorMsg { 231 | float: right; 232 | margin-left: 10px; 233 | margin-top: 10px; 234 | color: red; 235 | } 236 | 237 | .tit { 238 | height: 30px; 239 | } 240 | /*购物车*/ 241 | #main table{ 242 | margin: auto; 243 | margin-top: 80px; 244 | border-collapse: collapse; 245 | } 246 | 247 | #main table td{ 248 | width: 120px; 249 | text-align:center; 250 | border-bottom: 1px #e3e3e3 solid; 251 | padding: 10px; 252 | } 253 | 254 | .cart_info{ 255 | width: 700px; 256 | text-align: right; 257 | } 258 | 259 | .cart_span { 260 | margin-left: 20px; 261 | } 262 | 263 | .cart_span span{ 264 | color: red; 265 | font-size: 20px; 266 | margin: 10px; 267 | } 268 | 269 | .cart_span a , td a{ 270 | font-size: 20px; 271 | color: blue; 272 | } 273 | 274 | #header div span { 275 | margin: 10px; 276 | } 277 | 278 | #header div .um_span{ 279 | color: red; 280 | font-size: 25px; 281 | margin: 10px; 282 | } 283 | 284 | #header div a { 285 | color: blue; 286 | } 287 | 288 | 289 | .tableSpan{ 290 | font-size: medium; 291 | font-family: 黑体; 292 | } 293 | 294 | .wel_word{ 295 | font-size: 30px; 296 | float: left; 297 | margin-top: 30px; 298 | } 299 | 300 | .a-update{ 301 | font-size: medium; 302 | font-family: 黑体; 303 | color: blue; 304 | } 305 | .a-delete{ 306 | font-size: medium; 307 | font-family: 黑体; 308 | color: red; 309 | } 310 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/show.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 | 7 |
8 | 9 | 10 | 21 | 22 | 82 | 83 | 84 | 92 |
93 | 当前页面:查询学生信息 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 118 | 119 |
班级学号姓名成绩操作
115 |     116 | 117 |
120 |
121 |
122 | 123 |
124 |
125 |
126 | 127 | -------------------------------------------------------------------------------- /src/main/resources/templates/menu/stat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 统计 6 |
7 | 8 | 9 | 42 | 43 | 101 | 102 | 103 | 110 |
111 | 当前页面:统计学生信息 112 | 113 |
114 | 115 | 116 |
117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
班级人数平均分最高分最低分
135 |
136 |
137 |
138 |
139 |
140 | 141 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # 简介 2 |
3 | 4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 | 14 |
15 | 16 |
17 | 18 | 本文基于**SpringBoot+MyBatisPlus+Redis+Thymeleaf+Echarts**实现一个简单的学生成绩管理系统。它在上一[Spring+SpringMVC+Mybatis版本]((https://blog.csdn.net/qq_36937684/article/details/115924220))基础上使用了SpringBoot框架,优化了相关功能,增加了Echarts可视化功能。 19 | 20 | 21 | # 任务 22 |
23 |
24 | 25 | # 相关工作 26 | 27 | - [MySQL+java: 实现学生成绩管理系统(1.0版本)](https://blog.csdn.net/qq_36937684/article/details/108757156) 28 | - [整合Spring+Mybatis 学生成绩管理系统(完整代码)](https://blog.csdn.net/qq_36937684/article/details/113622364) 29 | - [JavaWeb+MySQL实现学生成绩管理系统(1.0版本完整代码)](https://blog.csdn.net/qq_36937684/article/details/114846331?spm=1001.2014.3001.5501) 30 | - [SSM 实现学生成绩管理系统(完整代码)](https://blog.csdn.net/qq_36937684/article/details/115924220) 31 | 32 | 本项目基于以上[项目](https://github.com/AsajuHuishi/StudentScoreManagementSystem_SSM)进行改进。主要内容有: 33 | - 使用SpringBoot一站式框架实现,代替Spring+SpringMVC+Mybatis多个框架,减少配置文件数量; 34 | - 使用SpringBoot的自定义错误页面、使用拦截器判断用户是否登录、使用注解式事务管理; 35 | - 前端使用HTML+Thymeleaf模板引擎,不再使用jsp; 36 | - 在注册页面使用Kaptcha验证码; 37 | - 使用Redis实现用户注册、登录功能; 38 | - 使用MyBatisPlus实现分页模型显示所有学生信息; 39 | - 使用Echarts对统计结果实现可视化; 40 | - 使用Slf4j实现日志功能。 41 | 42 | 更新日志(已经在github上更新) 43 | - 暂无 44 | 45 | # 项目结构 46 | 这是一个maven工程。 47 | 48 | ```bash 49 | ├─main 50 | │ ├─java 51 | │ │ └─indi 52 | │ │ └─huishi 53 | │ │ └─shizuo 54 | │ │ ├─config 配置类,包括WebMvcConfig MybatisPlusConfig 55 | │ │ ├─controller 表示层 56 | │ │ ├─dao 数据访问层 57 | │ │ │ └─impl 58 | │ │ ├─interceptor 拦截器 59 | │ │ ├─pojo 实体类 60 | │ │ ├─service 业务逻辑层 61 | │ │ │ └─impl 62 | │ │ └─util 工具包 63 | │ └─resources 64 | │ ├─static 静态资源 65 | │ │ ├─css 66 | │ │ ├─img 67 | │ │ └─script jquery echarts 68 | │ └─templates HTML页面 69 | │ ├─common 70 | │ ├─error 71 | │ ├─menu 72 | │ ├─test 73 | │ ├─useless 74 | │ └─user 75 | └─test 76 | └─java 77 | └─indi 78 | └─huishi 79 | └─shizuo 80 | ├─controller 81 | ├─service 82 | └─util 83 | 84 | ``` 85 |
86 | 87 | # 数据库 88 | 89 | 1.使用MySQL实现,和上一版本一致。 90 | 91 | ```sql 92 | USE student_score_ssm; 93 | 94 | CREATE TABLE student_score( 95 | id INT PRIMARY KEY AUTO_INCREMENT, 96 | NO VARCHAR(10) UNIQUE NOT NULL, 97 | NAME VARCHAR(20) NOT NULL, 98 | score FLOAT(20), 99 | class_name INT 100 | ); 101 | 102 | 103 | CREATE TABLE USER( 104 | id INT PRIMARY KEY AUTO_INCREMENT, 105 | username VARCHAR(20) UNIQUE, 106 | PASSWORD VARCHAR(20) NOT NULL, 107 | email VARCHAR(20) 108 | ); 109 | 110 | ``` 111 | 2.Redis实现用户注册和登录 112 | 113 | - set:保存用户名,确保用户名唯一 114 | ```bash 115 | 169.254.0.1:6379> SMEMBERS uname 116 | 1) "Linwenti" 117 | 2) "huishi" 118 | 169.254.0.1:6379> 119 | ``` 120 | - key-value: 保存用户名-密码 121 | 122 | ```bash 123 | 169.254.0.1:6379> get huishi 124 | "123456" 125 | 169.254.0.1:6379> get Linwenti 126 | "123456" 127 | ``` 128 | 129 | # 结果页面 130 | ## 主页 131 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021004637.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 132 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042102104968.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 133 | 134 | ## 查询 135 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021214493.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 136 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021257903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 137 | 查询异常 138 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021228421.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 139 | ## 增加 140 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021731287.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 141 | 142 | ## 修改 143 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2021042102170056.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 144 | ## 删除 145 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421021712884.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 146 | 147 | 148 | ## 统计 149 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210428015715371.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 150 | 151 | ## 登录 152 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421170512593.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 153 | 154 | ## 注册 155 | 156 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210514012258769.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2OTM3Njg0,size_16,color_FFFFFF,t_70#pic_center) 157 | 158 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /src/main/java/indi/huishi/shizuo/controller/StudentController.java: -------------------------------------------------------------------------------- 1 | package indi.huishi.shizuo.controller; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import indi.huishi.shizuo.pojo.Statistics; 7 | import indi.huishi.shizuo.pojo.Student; 8 | import indi.huishi.shizuo.service.StudentService; 9 | import indi.huishi.shizuo.util.BeanUtil; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.ui.Model; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpSession; 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * 控制器 28 | * @Author: Huishi 29 | * @Date: 2021/4/17 23:29 30 | */ 31 | @Controller 32 | @Slf4j 33 | @RequestMapping("/student") 34 | public class StudentController { 35 | 36 | @Autowired 37 | private StudentService studentService; 38 | private final String REDIRECT_PATH = "redirect:/student/show.action?pageNo="; 39 | private Integer pageSize = 8; 40 | 41 | /** 42 | * 跳转到指定页面显示 43 | * @param pageNo 44 | * @return 45 | */ 46 | @RequestMapping("/show.action") 47 | public String showAll (@RequestParam("pageNo") Integer pageNo, Model model, HttpSession session, HttpServletRequest request){ 48 | Page page = new Page<>(pageNo, pageSize); 49 | log.info("主页..查找第{}页",pageNo); 50 | IPage studentPage = studentService.selectPage(page, null); 51 | // 保存当前url 52 | model.addAttribute("page", studentPage); 53 | String url = request.getRequestURL().toString(); 54 | model.addAttribute("curr_url", url); 55 | log.info("url:{}",url); 56 | session.setAttribute("curr_url", url); 57 | // 将page保存在Session里面 58 | session.setAttribute("studentPage",studentPage); 59 | return "menu/show"; 60 | } 61 | 62 | /** 63 | * 根据要修改的id查询该学生信息 64 | * @param stuId 65 | * @return 66 | */ 67 | @RequestMapping("/queryById.action") 68 | public String queryById(Model model, String stuId){ 69 | Student student = studentService.queryById(stuId); 70 | log.info("查询学生{}",student); 71 | model.addAttribute("student",student); 72 | return "menu/update"; 73 | } 74 | 75 | /** 76 | * 根据修改之后的学生信息更新数据库,重定向回主页 77 | * @param student 来自接收的表单信息 78 | * @return 79 | */ 80 | @RequestMapping("/update.action") 81 | public String updateById (Student student, HttpSession session){ 82 | // System.out.println("updateById"+student); 83 | studentService.update(student); 84 | // 获取当前页 85 | Page studentPage = (Page)session.getAttribute("studentPage"); 86 | Integer pageNo = (int)studentPage.getCurrent(); 87 | // 重定向 显示全部 88 | System.out.println(REDIRECT_PATH + pageNo); 89 | return REDIRECT_PATH + pageNo; 90 | } 91 | 92 | /** 93 | * 删除该学生信息,重定向回主页 94 | * @param stuId 95 | * @return 96 | */ 97 | @RequestMapping("/delete.action") 98 | public String deleteById(String stuId, HttpSession session){ 99 | Integer id = Integer.parseInt(stuId); 100 | int delete = studentService.delete(id); 101 | // 获取当前页 102 | Page studentPage = (Page)session.getAttribute("studentPage"); 103 | Integer pageNo = (int)studentPage.getCurrent(); 104 | // 重定向 显示全部 105 | return REDIRECT_PATH + pageNo; 106 | } 107 | 108 | /** 109 | * 接收按学号查询的 学号,返回查找结果 110 | * @param 111 | * @return 112 | */ 113 | @RequestMapping("/queryByNo.action") 114 | public String queryByNo(@RequestParam("queryNo") String no, Model model){ 115 | System.out.println("输入学号"+no); 116 | Student student = studentService.queryByNo(no); 117 | if (student==null){ 118 | log.info("查找的学号{}不存在",no); 119 | model.addAttribute("status","404");//学号不存在状态码 120 | model.addAttribute("previous",no);//学号不存在状态码 121 | return "menu/queryByNo"; 122 | }else { 123 | log.info("查找的学号{}存在",no); 124 | List studentList = new ArrayList<>(); 125 | studentList.add(student); 126 | model.addAttribute("stuList", studentList); 127 | model.addAttribute("status","200");//学号不存在状态码 128 | return "menu/queryResult"; 129 | } 130 | } 131 | 132 | /** 133 | * 按姓名查询,返回查找结果 134 | * @param 135 | * @return 136 | */ 137 | @RequestMapping("/queryByName.action") 138 | public String queryByName(@RequestParam("queryName") String name, Model model){ 139 | System.out.println("输入姓名"+name); 140 | List studentList = studentService.queryByName(name); 141 | if (studentList.size()==0){ 142 | log.info("查找的学号{}不存在", name); 143 | model.addAttribute("status","404");//学号不存在状态码 144 | model.addAttribute("previous",name);//学号不存在状态码 145 | return "menu/queryByName"; 146 | }else { 147 | model.addAttribute("stuList",studentList); 148 | model.addAttribute("status","200");//学号不存在状态码 149 | return "menu/queryResult"; 150 | } 151 | } 152 | 153 | /** 154 | * 添加 学生信息 返回到主页 155 | */ 156 | @RequestMapping("/add.action") 157 | public String add(Student student, HttpSession session, Model model) throws RuntimeException{ 158 | // 首先查询学号是否已被使用(学号是unique) 159 | Student query = studentService.queryByNo(student.getNo()); 160 | System.out.println("查询"+query); 161 | // 获取当前页 162 | Page studentPage = (Page) session.getAttribute("studentPage"); 163 | Integer pageNo = (int)studentPage.getCurrent(); 164 | 165 | if(query == null) {// 学号未被使用 166 | int add = studentService.add(student); 167 | if (add == 0) { 168 | System.out.println("添加失败"); 169 | model.addAttribute("status", "400"); 170 | return "menu/add"; 171 | }else{ 172 | System.out.println("添加成功"); 173 | return REDIRECT_PATH + pageNo; 174 | } 175 | }else{ 176 | System.out.println("该学号已被使用"); 177 | model.addAttribute("status", "404"); 178 | return "menu/add"; 179 | } 180 | } 181 | 182 | /** 183 | * 统计学生信息 184 | */ 185 | @RequestMapping("/stat.action") 186 | public String stat(Model model) throws Exception { 187 | List statistics = studentService.statistics(); 188 | // 用于柱状图 189 | Map> resultMap = BeanUtil.objectList2MapList(statistics, new String[]{"minScore", "maxScore", "avgScore", "countStudent", "className"}); 190 | // 用于扇形图 191 | List> resultList = BeanUtil.objectList2ListMap(statistics); 192 | 193 | model.addAttribute("stat", statistics); 194 | model.addAttribute("statMap", resultMap); 195 | model.addAttribute("statList", resultList); 196 | return "menu/stat"; 197 | } 198 | 199 | /** 200 | * 跳转到指定页面 201 | * @param model 202 | * @param sourceName 203 | * @return 204 | */ 205 | @GetMapping("{sourceName}.html") 206 | public String jumpTo(Model model, @PathVariable("sourceName") String sourceName){ 207 | String string = new StringBuffer().append("menu/").append(sourceName).append(".html").toString(); 208 | return string; 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /src/main/resources/templates/common/page_naiv.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 150 | 151 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | --------------------------------------------------------------------------------