整合_整合redis - CSDN
精华内容
参与话题
  • 整合高通量组学数据集鉴定潜在机制联系的计算框架A computational framework to integrate high-throughput ‘-omics’ datase...

    整合高通量组学数据集鉴定潜在机制联系的计算框架

    A computational framework to integrate high-throughput ‘-omics’ datasets for the identification of potential mechanistic links

    Nature Protocols, [12.423], Article, 2018-10-31

    原文链接: http://dx.doi.org/10.1038/s41596-018-0064-z

    第一作者:Helle Krogh Pedersen

    通讯作者:Oluf Pedersen, Henrik Bjørn Nielsen

    主要单位:加州大学洛杉机分校,医学院

    其它作者:Sofia K Forslund,  Valborg Guðmundsdóttir,  Anders Østergaard Petersen, Falk Hildebrand, Tuulia Hyötyläinen, Trine Nielsen, Torben Hansen, Peer Bork, S Dusko Ehrlich, Søren Brunak, Matej Oresic

    导读

    微生物组和代谢组等高维数据和表型关联分析复杂、解读困难;

    分析的核心思想是降维:代谢组和微生物组物种通过数据驱动的聚类或分箱法降维;微生物组功能组成基于知识驱动如KEGG层级分类法降维;再筛选与表型显著相关的数据特征关联分析;

    研究人员可以整理多组学和表型数据,获得出版级关联分析结果图表,快速建立宿主和微生物组与疾病严重程度和治疗结果间的潜在联系;

    本计算框架由R脚本编写,可在个人电脑上1小时完成分析。

    摘要

    背景:我们最近发表了三管齐下的关联分析,整合宏基因组测序的人类肠道微生物组数据、非靶向的血清代谢组数据和宿主的生理指标。代谢组和微生物组数据是高维的,对于数据的整合提出了挑战。

    结果:我们提出了逐步的计算方法,详细讨论了降维技术的使用,以及解析异质类型数据整合的方法。降维的方法主要结合数据标准化和共丰度基因和代谢物的分箱,以及整理已知的生物学知识。使用先验知识克服微生物组物种功能冗余是我们方法的核心。使用此框架,其它研究人员可以整理多组学和表型数据(如队列中建立宿主和微生物组与疾病严重程度和治疗结果间的联系),建立三管齐下的联系,用于实验设置。

    结论:此框架最初是用于人类代谢组和微生物组研究,同样适用于其它物种和环境样本,同样适合整合其它组学如宏转录组、宏蛋白组。提供的R脚本在个人电脑上运行1小时左右。

    关键点

    知识点1. 原始数据的序列处理和和输出文件

    在整合分析前,数据必须进行处理。对于微生物组数据,包括:(i) 序列预处理,包括质控、过滤宿主序列;(ii) 构建参考基因集,或选择己发表的基因集作为参考;(iii) 比对参考序列定量;(iv) 样本标准化,以便于下游可比;(v) 对基因分箱为物种组,降低维度。

    对于代谢组数据,典型的处理流程包括:(i) 原始文件导入;(ii) 峰检测;(iii) 过滤和平滑;(iv) 峰列表去同位素;(v) 比对;(vi) 填补空白;(vii) 峰整合;(viii) 标准化;(ix) 最终峰或特征的鉴定

    尽管这些步骤不在本方法的范畴内,我们引用我们之前的文章,或补充方法来进一步描述微生物组和代谢组数据的预处理,以便产生本方法的输入文件。

    可用的示例数据保存于Git仓库 https://bitbucket.org/hellekp/clinical-micro-meta-integration 。它包括预处理微生物组、代谢组数据,以及397个体的表型信息,以及一系列功能微生物注释,宏基因组物种组和相应的微生物注释,以及手动注释的代谢物簇,详细描述在材料部分。

    这些文件经历了上面数不尽的预处理过程。对于新数据,必须按具体的实验方法、实验过程和分析平台来进行详细的预处理。

    图1. 整理人类表型、血清代谢组和肠道微生物组数据方法的流程图

    在微生物组和代谢组预处理后,代谢物聚类为共丰度簇(5-7),微生物组数据整理为物种组成和KEGG模块丰度矩阵。下一步,表型过滤阶段,只保留与表型统计显著的features(8-12),这些features将用于跨领域的相关或关联分析(13-15)。最终,使用leave-one-MGS-out分析鉴定KEGG模块和对应驱动物种与HOMA-IR关联(17-19)。FDR代表错误发现率,IR代表胰岛素抗性,IS代表胰岛素敏感,Mod模块,neg负相关,pos正相关。本图修改自Pdersen等出版书籍中图片,己获授权。

    表1. 基于数据和知识的降维方法

    微生物组数据驱动的方法主要有Binning,而知识驱动的方法主要是各功能注释数据库的层级分类。

    知识点2. 驱动物种分析背后的原理

    图2. leave-one-MGS-out方法鉴定驱动物种的原理

    为了简化说明原理,我们以一个KEGG模块为例,它包括三个KOs(KO1,KO2,KO3),并且只有一个KEGG模块与HOMA-IR表型用于关联分析

    a. 计算Spearman相关系数(SCC)这三个KO与HOMA-IR相关,b. 这三个KO相关的中位数使用代表KEGG信号。

    c, 重复a,b方法于所有基因,组成假定的MGS,移除MGSi

    d, 计算移除前后的的信号变化。最后c,d步来计算每个MGS。可以鉴定物种驱动的KEGG模块。

    图3. 微生物组功能与表型和代谢物簇的关联

    流程15步产生的样本图。表型组、肠道菌群和代谢组的关联图谱。

    左侧面板为KEGG模块相关的表型,颜色为关联的方向,红为负相关,蓝为正相关,灰为不显著。右则为KEGG与代谢模块间相关,颜色代表Spearman相关系数,并标注FDR显著性统计。

    结果的解释,我们看到KEGG模块和代谢簇分为两组:代谢偏好和不偏好两类由胰岛素抗性决定,发现广泛的、正或负相关的、跨组学的关联;跨领域的关联分析,经常可以看到规律。但前提是,在一方向特征在相同的维度上参与,如健康或疾病在相关稳定时,可以预测一些相关的行为。

    图4. 以BCAA生物合成模块为例显示评估相关细节

    leave-one-MGS-out第19步产生的结果样本图展示整合的BCAA生物合成模块(包括M00019, M00570, M00535和M00432共13个KOs)。

    a. 模块中KOs的SCC分布和背景(蓝)比较;

    b. 关键模块在总体中去除,去关联中位数的影响;

    c. 基于背景校正的相关系数原理。

    表2. 常见问题和解决方案

    猜你喜欢

    10000+:菌群分析 宝宝与猫狗 梅毒狂想曲 提DNA发Nature Cell专刊 肠道指挥大脑

    系列教程:微生物组入门 Biostar 微生物组  宏基因组

    专业技能:学术图表 高分文章 生信宝典 不可或缺的人

    一文读懂:宏基因组 寄生虫益处 进化树

    必备技能:提问 搜索  Endnote

    文献阅读 热心肠 SemanticScholar Geenmedical

    扩增子分析:图表解读 分析流程 统计绘图

    16S功能预测   PICRUSt  FAPROTAX  Bugbase Tax4Fun

    在线工具:16S预测培养基 生信绘图

    科研经验:云笔记  云协作 公众号

    编程模板: Shell  R Perl

    生物科普:  肠道细菌 人体上的生命 生命大跃进  细胞暗战 人体奥秘  

    写在后面

    为鼓励读者交流、快速解决科研困难,我们建立了“宏基因组”专业讨论群,目前己有国内外5000+ 一线科研人员加入。参与讨论,获得专业解答,欢迎分享此文至朋友圈,并扫码加主编好友带你入群,务必备注“姓名-单位-研究方向-职称/年级”。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍末解决群内讨论,问题不私聊,帮助同行。

    学习16S扩增子、宏基因组科研思路和分析实战,关注“宏基因组”

    点击阅读原文,跳转最新文章目录阅读

    展开全文
  • SpringBoot是Spring框架的扩展,其设计目的是用来简化Spring...下面将介绍SpringBoot与MyBatis的整合。 1、创建数据表 在MySQL数据库中创建用户信息表(tb_user),并添加数据。 -- 判断数据表是否存在,存在则删除

    SpringBoot是Spring框架的扩展,其设计目的是用来简化Spring应用的初始搭建以及开发过程,使得开发变得更快、更高效、更自动化。MyBatis是一款优秀的持久层框架,它支持定制化SQL、存储过程、以及高级映射。MyBatis3提供的注解可以取代XML。例如,使用注解@Select直接编写SQL完成数据查询。

    下面将介绍SpringBoot与MyBatis的整合步骤。

    1、创建数据表

    在MySQL数据库中创建用户信息表(tb_user),并添加数据。

    -- 判断数据表是否存在,存在则删除
    DROP TABLE IF EXISTS tb_user;
     
    -- 创建“用户信息”数据表
    CREATE TABLE IF NOT EXISTS tb_user
    ( 
    	user_id INT AUTO_INCREMENT PRIMARY KEY COMMENT '用户编号',
    	user_account VARCHAR(50) NOT NULL COMMENT '用户账号',
    	user_password VARCHAR(50) NOT NULL COMMENT '用户密码',
    	blog_url VARCHAR(50) NOT NULL COMMENT '博客地址',
    	blog_remark VARCHAR(50) COMMENT '博客备注'
    ) COMMENT = '用户信息表';
     
    -- 添加数据
    INSERT INTO tb_user(user_account,user_password,blog_url,blog_remark) VALUES('pan_junbiao的博客','123456','https://blog.csdn.net/pan_junbiao','您好,欢迎访问 pan_junbiao的博客');

     

    2、创建项目

    (1)创建SpringBoot项目,项目结构如下图:

    (2)添加pom.xml配置信息

    在pom.xml配置文件中添加MyBatis、 MySQL的JDBC数据库驱动、Thymeleaf等依赖。

    <!-- MyBatis与SpringBoot整合依赖 -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>
    
    <!-- MySQL的JDBC数据库驱动 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.20</version>
    </dependency>
    
    <!-- 引入Thymeleaf模板引擎 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    (3)配置相关信息

    将默认的application.properties文件的后缀修改为“.yml”,即配置文件名称为:application.yml,并配置以下信息:

    spring:
      #DataSource数据源
      datasource:
        url: jdbc:mysql://localhost:3306/db_admin?useSSL=false&amp
        username: root
        password: 123456
        driver-class-name: com.mysql.cj.jdbc.Driver
      #使用Thymeleaf模板引擎
      thymeleaf:
        mode: HTML5
        encoding: UTF-8
        cache: false  #使用Thymeleaf模板引擎,关闭缓存
        servlet:
          content-type: text/html
    
    #MyBatis配置
    mybatis:
      type-aliases-package: com.pjb.entity #别名定义
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #指定 MyBatis 所用日志的具体实现,未指定时将自动查找
        map-underscore-to-camel-case: true #开启自动驼峰命名规则(camel case)映射
        lazy-loading-enabled: true #开启延时加载开关
        aggressive-lazy-loading: false #将积极加载改为消极加载(即按需加载),默认值就是false
        lazy-load-trigger-methods: "" #阻挡不相干的操作触发,实现懒加载
        cache-enabled: true #打开全局缓存开关(二级环境),默认值就是true

    2.1 创建实体类(Entity层)

    在com.pjb.entity包中,创建UserInfo类(用户信息实体类)。

    package com.pjb.entity;
    
    /**
     * 用户信息实体类
     * @author pan_junbiao
     **/
    public class UserInfo
    {
        private int userId; //用户编号
        private String userAccount; //用户账号
        private String userPassword; //用户密码
        private String blogUrl; //博客地址
        private String blogRemark; //博客备注
    
        //省略getter与setter方法...
    }

    2.2 数据库映射层(Mapper层)

    在com.pjb.mapper包中,创建UserMapper接口(用户信息Mapper动态代理接口)。

    package com.pjb.mapper;
    
    import com.pjb.entity.UserInfo;
    import org.apache.ibatis.annotations.*;
    import org.springframework.stereotype.Repository;
    
    /**
     * 用户信息Mapper动态代理接口
     * @author pan_junbiao
     **/
    @Repository
    public interface UserMapper
    {
        /**
         * 新增用户,并获取自增主键
         */
        @Insert("INSERT INTO tb_user(user_account,user_password,blog_url,blog_remark) VALUES(#{userAccount},#{userPassword},#{blogUrl},#{blogRemark})")
        @Options(useGeneratedKeys = true, keyColumn = "user_id", keyProperty = "userId")
        //或者:@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyColumn = "user_id", keyProperty = "userId",before = false, resultType = Integer.class)
        public int insertUser(UserInfo userInfo);
    
        /**
         * 修改用户
         */
        @Update("UPDATE tb_user SET user_account = #{userAccount} ,user_password = #{userPassword} ,blog_url=#{blogUrl} ,blog_remark=#{blogRemark} WHERE user_id = #{userId}")
        public int updateUser(UserInfo userInfo);
    
        /**
         * 删除用户
         */
        @Delete("DELETE FROM tb_user WHERE user_id = #{userId}")
        public int deleteUser(int userId);
    
        /**
         * 根据用户ID,获取用户信息
         */
        @Select("SELECT * FROM tb_user WHERE user_id = #{userId}")
        public UserInfo getUserById(int userId);
    }

    2.3 实现实体和数据表的映射关系

    实现实体和数据表的映射关系可以在Mapper类上添加@Mapper注解,如下代码:

    /**
     * 用户信息Mapper动态代理接口
     * @author pan_junbiao
     **/
    @Mapper
    @Repository
    public interface UserMapper
    {
        //省略其他代码...
    }

    但是建议以后直接在SpringBoot启动类中加 @MapperScan("com.pjb.mapper") 注解,这样会比较方便,不需要对每个Mapper都添加@Mapper注解。

    package com.pjb;
    
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * SpringBoot启动类
     * @author pan_junbiao
     **/
    @MapperScan("com.pjb.mapper")
    @SpringBootApplication
    public class SpringbootMybatisDemoApplication
    {
        public static void main(String[] args)
        {
            SpringApplication.run(SpringbootMybatisDemoApplication.class, args);
        }
    }
    

    2.4 业务逻辑层(Service层)

    在com.pjb.service包下,创建UserService接口(用户信息业务逻辑接口)。

    package com.pjb.service;
    
    import com.pjb.entity.UserInfo;
    
    /**
     * 用户信息业务逻辑接口
     * @author pan_junbiao
     **/
    public interface UserService
    {
        /**
         * 新增用户,并获取自增主键
         */
        public int insertUser(UserInfo userInfo);
    
        /**
         * 修改用户
         */
        public int updateUser(UserInfo userInfo);
    
        /**
         * 删除用户
         */
        public int deleteUser(int userId);
    
        /**
         * 根据用户ID,获取用户信息
         */
        public UserInfo getUserById(int userId);
    }

    在com.pjb.service.impl包下,创建UserServiceImpl类(用户信息业务逻辑类)。

    package com.pjb.service.impl;
    
    import com.pjb.entity.UserInfo;
    import com.pjb.mapper.UserMapper;
    import com.pjb.service.UserService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    /**
     * 用户信息业务逻辑类
     * @author pan_junbiao
     **/
    @Service
    public class UserServiceImpl implements UserService
    {
    
        @Autowired
        private UserMapper userMapper;
    
        /**
         * 新增用户,并获取自增主键
         */
        public int insertUser(UserInfo userInfo)
        {
            return userMapper.insertUser(userInfo);
        }
    
        /**
         * 修改用户
         */
        public int updateUser(UserInfo userInfo)
        {
            return userMapper.updateUser(userInfo);
        }
    
        /**
         * 删除用户
         */
        public int deleteUser(int userId)
        {
            return userMapper.deleteUser(userId);
        }
    
        /**
         * 根据用户ID,获取用户信息
         */
        public UserInfo getUserById(int userId)
        {
            return userMapper.getUserById(userId);
        }
    }

    2.5 控制器方法(Controller层)

    在com.pjb.controller包中,创建UserController类(用户控制器),实现用户数据的查询、新增、修改、删除,并实现数据的返回。

    package com.pjb.controller;
    
    import com.pjb.entity.UserInfo;
    import com.pjb.service.UserService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.servlet.ModelAndView;
    
    /**
     * 用户控制器
     * @author pan_junbiao
     **/
    @Controller
    @RequestMapping("/user")
    public class UserController
    {
        @Autowired
        private UserService userService;
    
        /**
         * 新增用户
         */
        @RequestMapping("/insertUser")
        @ResponseBody
        public boolean insertUser()
        {
            boolean result = false;
    
            //创建新用户
            UserInfo userInfo = new UserInfo();
            userInfo.setUserAccount("pan_junbiao的博客");
            userInfo.setUserPassword("123456");
            userInfo.setBlogUrl("https://blog.csdn.net/pan_junbiao");
            userInfo.setBlogRemark("您好,欢迎访问 pan_junbiao的博客");
            int count = userService.insertUser(userInfo);
    
            //返回结果
            result = count > 0 ? true : false;
            return true;
        }
    
        /**
         * 修改用户
         */
        @RequestMapping("/updateUser")
        @ResponseBody
        public boolean updateUser(int userId)
        {
            boolean result = false;
    
            //创建修改用户
            UserInfo userInfo = new UserInfo();
            userInfo.setUserId(userId);
            userInfo.setUserAccount("pan_junbiao的博客_02");
            userInfo.setUserPassword("123456");
            userInfo.setBlogUrl("https://blog.csdn.net/pan_junbiao");
            userInfo.setBlogRemark("您好,欢迎访问 pan_junbiao的博客");
            int count = userService.updateUser(userInfo);
    
            //返回结果
            result = count > 0 ? true : false;
            return true;
        }
    
        /**
         * 删除用户
         */
        @RequestMapping("/deleteUser")
        @ResponseBody
        public boolean deleteUser(int userId)
        {
            boolean result = false;
    
            //执行删除用户
            int count = userService.deleteUser(userId);
    
            //返回结果
            result = count > 0 ? true : false;
            return true;
        }
    
    
        /**
         * 根据用户ID,获取用户信息
         */
        @RequestMapping("/getUserById")
        public ModelAndView getUserById(int userId)
        {
            UserInfo userInfo = userService.getUserById(userId);
    
            //返回结果
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.addObject("userInfo", userInfo);
            modelAndView.setViewName("userInfo.html");
            return modelAndView;
        }
    }

     

    3、综合实例

    【实例】实现用户信息的查询、新增、修改、删除操作。

    3.1 查询用户

    查询用户信息,执行结果如下图:

    在resources/templates目录下,创建 userInfo.html 用户信息显示页面。

    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>用户信息</title>
        <meta name="author" content="pan_junbiao的博客">
        <style>
            table { border-collapse: collapse; margin-bottom: 10px}
            table,table tr th, table tr td { border:1px solid #000000; padding: 5px 10px;}
        </style>
    </head>
    <body>
    <div align="center">
        <table>
            <caption>用户信息</caption>
            <tr>
                <th>用户ID:</th>
                <td th:text="${userInfo.userId}"></td>
            </tr>
            <tr>
                <th>用户姓名:</th>
                <td th:text="${userInfo.userAccount}"></td>
            </tr>
            <tr>
                <th>博客地址:</th>
                <td th:text="${userInfo.blogUrl}"></td>
            </tr>
            <tr>
                <th>博客信息:</th>
                <td th:text="${userInfo.blogRemark}"></td>
            </tr>
        </table>
    </div>
    </body>
    </html>

    编写控制器方法:

    @Autowired
    private UserService userService;
    
    /**
     * 根据用户ID,获取用户信息
     * @author pan_junbiao
     */
    @RequestMapping("/getUserById")
    public ModelAndView getUserById(int userId)
    {
        UserInfo userInfo = userService.getUserById(userId);
    
        //返回结果
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userInfo", userInfo);
        modelAndView.setViewName("userInfo.html");
        return modelAndView;
    }

    执行结果: 

    控制台打印的SQL语句与执行结果如下图:

    3.2 新增用户

    新增用户信息,编写控制器方法:

    @Autowired
    private UserService userService;
    
    /**
     * 新增用户
     * @author pan_junbiao
     */
    @RequestMapping("/insertUser")
    @ResponseBody
    public boolean insertUser()
    {
        boolean result = false;
    
        //创建新用户
        UserInfo userInfo = new UserInfo();
        userInfo.setUserAccount("pan_junbiao的博客");
        userInfo.setUserPassword("123456");
        userInfo.setBlogUrl("https://blog.csdn.net/pan_junbiao");
        userInfo.setBlogRemark("您好,欢迎访问 pan_junbiao的博客");
        int count = userService.insertUser(userInfo);
    
        //返回结果
        result = count > 0 ? true : false;
        return true;
    }

    执行结果:

    控制台打印的SQL语句与执行结果如下图:

    3.3 修改用户

    修改用户信息,编写控制器方法:

    @Autowired
    private UserService userService;
    
    /**
     * 修改用户
     * @author pan_junbiao
     */
    @RequestMapping("/updateUser")
    @ResponseBody
    public boolean updateUser(int userId)
    {
        boolean result = false;
    
        //创建修改用户
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(userId);
        userInfo.setUserAccount("pan_junbiao的博客_02");
        userInfo.setUserPassword("123456");
        userInfo.setBlogUrl("https://blog.csdn.net/pan_junbiao");
        userInfo.setBlogRemark("您好,欢迎访问 pan_junbiao的博客");
        int count = userService.updateUser(userInfo);
    
        //返回结果
        result = count > 0 ? true : false;
        return true;
    }

    执行结果:

    控制台打印的SQL语句与执行结果如下图:

    3.4 删除用户

    删除用户信息,编写控制器方法:

    @Autowired
    private UserService userService;
    
    /**
     * 删除用户
     * @author pan_junbiao
     */
    @RequestMapping("/deleteUser")
    @ResponseBody
    public boolean deleteUser(int userId)
    {
        boolean result = false;
    
        //执行删除用户
        int count = userService.deleteUser(userId);
    
        //返回结果
        result = count > 0 ? true : false;
        return true;
    }

    执行结果:

    控制台打印的SQL语句与执行结果如下图:

     

    展开全文
  • 综合案例-整合办公系统后台模块 1、配置虚拟主机(如www.think.com) 2、配置hosts文件并重启Apache服务器 3、复制ThinkPHP核心文件到项目的目录中(如think目录) 4、创建Zend工程 5、创建index.php入口文件...

    综合案例-整合办公系统后台模块

    1、配置虚拟主机(如www.think.com

    2、配置hosts文件并重启Apache服务器

    3、复制ThinkPHP核心文件到项目的目录中(如think目录)

    4、创建Zend工程

    5、创建index.php入口文件(编写四步走)

    6、划分项目前后台模块

    设置配置文件(./Application/Common/Conf/config.php)

    7、创建Public控制器并定义login方法

    编写控制器三步走

    8、设置URL调度模式

    9、复制模板资源到Public资源目录下的Admin文件中

    10、复制login.html到./Application/Admin/View/Public文件夹中

    11、更改模板文件中的路径(用到模板替换)

    替换页面中的images/css/js路径,最终效果如下图所示:

    12、在Admin模块下创建IndexController控制器

    编写代码如下:

    13、引入index.html模板到./Application/Admin/View/Index文件夹下

    14、更改index.html模板路径

    15、更改index.html模板文件中的框架,如下图所示:

    16、在Index控制器下定义home方法

    17、更改home.html模板文件路径,最终效果如下图所示:

     

    转载于:https://www.cnblogs.com/nyxd/p/5366084.html

    展开全文
  • 1. 使用技术 1.1 后端 SpringCloud+SpringBoot+maven2+web+MySQL+xml+pagehelper+lombok+jwt+ras+BaseResult Eureka 注册中心 + Eureka 客户端

    1. 使用技术

    1.1 后端

    • SpringCloud+SpringBoot+maven2+web+MySQL+xml+pagehelper+lombok+jwt+ras+BaseResult
    • Eureka 注册中心 + Eureka 客户端+Zuul网关 + 过滤器

    1.2 前端

    • vue渐进式JavaScript框架

    2. 需完成功能

    2.1 功能1:用户登录

    前端代码

    api.js

    /** ajax axios */
    import axios from 'axios'
    import { Message } from 'element-ui'
    
    /** axios 基本项设置 */
    axios.defaults.baseURL = 'http://localhost:10010/api'
    axios.defaults.timeout = 3000
    
    // 全局ajax错误处理
    // axios.interceptors.response.use(response => {
    //   return response
    // }, error => {
    //   Message.error(error.message)
    //   return Promise.reject(error)
    // })
    
    /** 发送请求 */
    export function login (user) {
      return axios.post('/userservice/user/login', user)
    }
    export function FindClassesForPageNum (ClassesPi) {
      return axios.get('/studentservice/classes/FindClassesForPageNum',{
        params:ClassesPi
      } )
    }
    export function Findteacher1list (t1) {
      return axios.get('/studentservice/classes/Findteacher1list/' +t1)
    }
    export function Findteacher2list (t2) {
      return axios.get('/studentservice/classes/Findteacher2list/' +t2)
    }
    export function Findteacher3list (t3) {
      return axios.get('/studentservice/classes/Findteacher3list/' + t3)
    }
    export function addClasses (classes) {
      return axios.post('/studentservice/classes/addClasses', classes)
    }
    export function DeleteClassesByCid (ids) {
      return axios.delete('/studentservice/classes/DeleteClassesByCid/' + ids)
    }
    export function FindByClassesByCid (cid) {
      return axios.get('/studentservice/classes/FindByClassesByCid/' + cid)
    }
    export function UpdateClasses (classes) {
      return axios.put('/studentservice/classes/UpdateClasses', classes)
    }
    export function FindStudentListForPageNum (studentPi) {
      return axios.get('/studentservice/student/FindStudentListForPageNum', {
        params:studentPi
      })
    }
    export function Findclasses () {
      return axios.get('/studentservice/student/Findclasses')
    }
    export function addStudent (student) {
      return axios.post('/studentservice/student/addStudent', student)
    }
    export function deleteStudentBysid (ids) {
      return axios.delete('/studentservice/student/deleteStudentBysid/'+ids)
    }
    export function FindStudent (sid) {
      return axios.get('/studentservice/student/FindStudent/'+sid)
    }
    
    

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    <template>
      <div class="login">
          <el-card class="login-box-card">
      <div slot="header" class="clearfix">
        <el-button type="text" icon="el-icon-s-home">综合案例</el-button>
      </div>
      <div>
      <el-form ref="loginFrom" :model="LoginUser" label-width="80px">
     <el-form-item label="用户名">
        <el-input v-model="LoginUser.user_name"></el-input>
      </el-form-item>
       <el-form-item label="密码">
        <el-input show-password v-model="LoginUser.password"></el-input>
      </el-form-item>
        <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
      </el-form>
      </div>
    </el-card>
      </div>
    </template>
    
    <script>
    import { login } from '../api'
    export default {
      data() {
          return {
              LoginUser: {},
              errorMsg:''
          }
      },
      methods: {
          async login() {
            let { data } = await login(this.LoginUser)
            if(data.code == 1){
              this.$message.success(data.message)
              this.$router.push('/home')
            }else{
              this.$message.error(data.message)
            }
          }
      },
    }
    </script>
    
    <style>
    .login-box-card {
        width: 480px;
      }
       .login {
            height: 100%;
            display: flex;              /* css3 新取值,允许居中 */
            align-items: center;        /* 上下居中*/
            justify-content: center;   /* 左右居中 */
        }
    </style>
    

    后端代码

    在这里插入图片描述

    • pom依赖
        <dependencies>
            <!--web起步依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!-- Eureka客户端 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
            <!--通用mapper起步依赖-->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>2.0.4</version>
            </dependency>
            <!--MySQL数据库驱动-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <dependency>
                <groupId>com.czxy.cloud</groupId>
                <artifactId>Exam_common</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
    • application.yml文件
    server:
      port: 9090
    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/cloud_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
        username: root
        password: 947411
      application:
        name: userservice
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:10086/eureka/
    
    • UserApplication启动类
    package com.czxy;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import tk.mybatis.spring.annotation.MapperScan;
    
    @SpringBootApplication
    @EnableEurekaClient
    @MapperScan(basePackages = "com.czxy.mapper")
    public class UserApplicatioon {
        public static void main(String[] args) {
            SpringApplication.run(UserApplicatioon.class,args);
        }
    }
    
    
    • domain对象类
    package com.czxy.domain;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    @Table(name = "tb_user")
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class User {
        @Id
        private Integer id;
        private String user_name;
        private String password;
    }
    
    • mapper 通用mapper类
    package com.czxy.mapper;
    
    import com.czxy.domain.User;
    import tk.mybatis.mapper.common.Mapper;
    
    public interface UserMapper extends Mapper<User> {
    }
    
    
    • service
    package com.czxy.service;
    
    import com.czxy.domain.User;
    
    public interface UserService {
        /**
         * 登录用户
         * @param user
         * @return
         */
        User login(User user);
    }
    
    package com.czxy.service.impl;
    
    import com.czxy.domain.User;
    import com.czxy.mapper.UserMapper;
    import com.czxy.service.UserService;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    import tk.mybatis.mapper.entity.Example;
    
    import javax.annotation.Resource;
    
    @Service
    @Transactional
    public class UserServiceImpl implements UserService {
        @Resource
        private UserMapper userMapper;
        /**
         * 登录用户
         * @param user
         * @return
         */
        @Override
        public User login(User user) {
            Example example = new Example(User.class);
            Example.Criteria c = example.createCriteria();
            c.andEqualTo("user_name",user.getUser_name());
            c.andEqualTo("password",user.getPassword());
            User bean = userMapper.selectOneByExample(example);
            if (bean==null){
                return null;
            }
            return bean;
        }
    }
    
    
    • controller 控制类
    package com.czxy.controller;
    
    import com.czxy.domain.User;
    import com.czxy.service.UserService;
    import com.czxy.vo.BaseResult;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.annotation.Resource;
    
    @RestController
    @RequestMapping("/user")
    public class UserController {
        // private static final  String priKeyPath = "D:\\ras\\ras.pri";
        @Resource
        private UserService userService;
    
        /**
         * 登录用户
         * @param user
         * @return
         */
        @PostMapping("/login")
        public BaseResult login(@RequestBody User user){
                //如果登录成功,将数据存入私钥中
                User loginUser = userService.login(user);
                if (loginUser!=null){
                    // String token = JwtUtils.generateToken(loginUser, 60 * 5, RasUtils.getPrivateKey(priKeyPath));
                    return BaseResult.ok("登录成功",loginUser);
                }else{
                    return BaseResult.error("用户名或密码错误");
                }
            }
    }
    
    

    2.2 功能2:布局

    在这里插入图片描述

    <template>
      <div>
    <el-container>
      <el-header>综合案例</el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu default-active="2" class="el-menu-vertical-demo" router>
            <el-submenu index="1_">
              <template slot="title">
              <i class="el-icon-location"></i>
              <span>班级管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/addClasses">添加班级</el-menu-item>
              <el-menu-item index="/classesList">班级列表</el-menu-item>
            </el-menu-item-group>
            </el-submenu>
             <el-submenu index="2_">
              <template slot="title">
              <i class="el-icon-location"></i>
              <span>学生管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/addStudent">添加学生</el-menu-item>
              <el-menu-item index="/studentList">学生列表</el-menu-item>
            </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
      </div>
    </template>
    
    <script>
    export default {
    
    }
    </script>
    
    <style>
      .el-header, .el-footer {
        background-color: #B3C0D1;
        color: #333;
        text-align: center;
        line-height: 60px;
      }
    </style>
    
    

    2.3 功能3:添加班级

    在这里插入图片描述

    前端代码

    <template>
      <div>
          <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/classesList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/">班级管理</a></el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/addClasses">添加班级</a></el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
    <div>
        <el-card class="classes-box-card">
      <div>
          <el-form ref="classesFrom" :model="classes" label-width="100px">
            <el-form-item label="班级名称">
                <el-input v-model="classes.cname"></el-input>
            </el-form-item>
            <el-form-item label="授课老师">
                <el-select v-model="classes.teacher1_id" placeholder="请选择授课老师">
                    <el-option v-for="(t1, index1) in teacher1list" :key="index1" :value="t1.tid" :label="t1.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item label="助理老师">
                <el-select v-model="classes.teacher2_id" placeholder="请选择助理老师">
                    <el-option v-for="(t2, index2) in teacher2list" :key="index2" :value="t2.tid" :label="t2.tname"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="辅导员老师">
                <el-select v-model="classes.teacher3_id" placeholder="请选择辅导员老师">
                    <el-option v-for="(t3, index3) in teacher3list" :key="index3" :value="t3.tid" :label="t3.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="addClasses">添加班级</el-button>
            </el-form-item>
                
          </el-form>
      </div>
    </el-card>
    </div>
      </div>
    </template>
    
    <script>
    import { Findteacher1list, Findteacher2list, Findteacher3list, addClasses} from '../../api'
    import { async } from 'q'
    export default {
    data() {
        return {
            classes: {},
            teacher1list:[],
            teacher2list:[],
            teacher3list:[],
            t1:1,
            t2:2,
            t3:3
        }
    
    },
    created() {
        this.Findteacher1list()
        this.Findteacher2list()
        this.Findteacher3list()
    },
     methods: {
         async Findteacher1list() {
           let { data } = await Findteacher1list(this.t1)
           this.teacher1list = data.data
         },
          async Findteacher2list() {
           let { data } = await Findteacher2list(this.t2)
           this.teacher2list = data.data
         },
          async Findteacher3list() {
           let { data } = await Findteacher3list(this.t3)
           this.teacher3list = data.data
         },
         async addClasses() {
           let { data } = await addClasses(this.classes)
           if (data.code == 1) {
               this.$message.success(data.message)
               this.$router.push('/classesList')
           }
         }
     },
    }
    </script>
    
    <style>
     .classes-box-card {
        width: 480px;
      }
    </style>
    

    后端代码

    在这里插入图片描述

    • domain 对象类
    package com.czxy.domain;
    
    import javax.persistence.Id;
    import javax.persistence.Table;
    import java.io.Serializable;
    @Table(name = "tb_class")
    public class Classes implements Serializable {
        @Id
        private Integer cid;
        private String cname;
        private Integer teacher1_id;
        private Teacher teacher1;
        private Integer teacher2_id;
        private Teacher teacher2;
        private Integer teacher3_id;
        private Teacher teacher3;
    
    
        @Override
        public String toString() {
            return "Classes{" +
                    "cid=" + cid +
                    ", cname='" + cname + '\'' +
                    ", teacher1_id=" + teacher1_id +
                    ", teacher1=" + teacher1 +
                    ", teacher2_id=" + teacher2_id +
                    ", teacher2=" + teacher2 +
                    ", teacher3_id=" + teacher3_id +
                    ", teacher3=" + teacher3 +
                    '}';
        }
    
        public Classes() {
        }
    
        public Integer getCid() {
    
            return cid;
        }
    
        public void setCid(Integer cid) {
            this.cid = cid;
        }
    
        public String getCname() {
            return cname;
        }
    
        public void setCname(String cname) {
            this.cname = cname;
        }
    
        public Integer getTeacher1_id() {
            return teacher1_id;
        }
    
        public void setTeacher1_id(Integer teacher1_id) {
            this.teacher1_id = teacher1_id;
        }
    
        public Teacher getTeacher1() {
            return teacher1;
        }
    
        public void setTeacher1(Teacher teacher1) {
            this.teacher1 = teacher1;
        }
    
        public Integer getTeacher2_id() {
            return teacher2_id;
        }
    
        public void setTeacher2_id(Integer teacher2_id) {
            this.teacher2_id = teacher2_id;
        }
    
        public Teacher getTeacher2() {
            return teacher2;
        }
    
        public void setTeacher2(Teacher teacher2) {
            this.teacher2 = teacher2;
        }
    
        public Integer getTeacher3_id() {
            return teacher3_id;
        }
    
        public void setTeacher3_id(Integer teacher3_id) {
            this.teacher3_id = teacher3_id;
        }
    
        public Teacher getTeacher3() {
            return teacher3;
        }
    
        public void setTeacher3(Teacher teacher3) {
            this.teacher3 = teacher3;
        }
    }
    
    
    package com.czxy.domain;
    
    import javax.persistence.Id;
    import javax.persistence.Table;
    import java.io.Serializable;
    @Table(name = "tb_teacher")
    
    public class Teacher implements Serializable{
        @Id
        private Integer tid;
        private String tname;
        private Integer type;
    
        @Override
        public String toString() {
            return "Teacher{" +
                    "tid=" + tid +
                    ", tname='" + tname + '\'' +
                    ", type=" + type +
                    '}';
        }
    
        public Integer getTid() {
            return tid;
        }
    
        public void setTid(Integer tid) {
            this.tid = tid;
        }
    
        public String getTname() {
            return tname;
        }
    
        public void setTname(String tname) {
            this.tname = tname;
        }
    
        public Integer getType() {
            return type;
        }
    
        public void setType(Integer type) {
            this.type = type;
        }
    
        public Teacher(Integer tid, String tname, Integer type) {
    
            this.tid = tid;
            this.tname = tname;
            this.type = type;
        }
    
        public Teacher() {
    
        }
    }
    
    
    • mapper 配置类
    package com.czxy.mapper;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import org.apache.ibatis.annotations.*;
    import tk.mybatis.mapper.common.Mapper;
    
    import java.util.List;
    
    public interface ClassesMapper extends Mapper<Classes> {}
    
    
    package com.czxy.mapper;
    
    import com.czxy.domain.Teacher;
    import org.apache.ibatis.annotations.Param;
    import org.apache.ibatis.annotations.Result;
    import org.apache.ibatis.annotations.Results;
    import org.apache.ibatis.annotations.Select;
    import tk.mybatis.mapper.common.Mapper;
    
    import java.util.List;
    
    public interface TeacherMapper extends Mapper<Teacher> {}
    
    • service和serviceImpl
    package com.czxy.service;
    import com.czxy.domain.Classes;
    
    public interface ClassesService {
      /**
        * 添加班级
        * @param classes
        * @return
        */
       void addClasses(Classes classes);}
    
    
    package com.czxy.service.impl;
    import com.czxy.domain.Classes;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.ClassesService;
    import javax.annotation.Resource;
    @Service
    @Transactional
    public class ClassesServiceImpl implements ClassesService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
    
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @PostMapping("/addClasses")
        public BaseResult addClasses(@RequestBody Classes classes){
            classesService.addClasses(classes);
            return BaseResult.ok("添加成功");
        }
    }
    
    • controller 控制器
    package com.czxy.controller;
    import com.czxy.domain.Classes;
    import javax.annotation.Resource;
    @RestController
    @RequestMapping("/classes")
    public class ClassesController {
        @Resource
        private ClassesService classesService;
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @PostMapping("/addClasses")
        public BaseResult addClasses(@RequestBody Classes classes){
            classesService.addClasses(classes);
            return BaseResult.ok("添加成功");
        }
    
    

    2.4 功能4:班级列表(基本列表 + 分页 + 条件)

    在这里插入图片描述

    前端代码

    <template>
     <div>
        <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/classesList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/">班级管理</a></el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/classList">班级列表</a></el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
       <el-card class="box-card">
      <div>
     <div slot="header" >
              <el-form :inline="true" :model="ClassesPi" size="mini" class="demo-form-inline">
                <el-form-item label="班级名称">
                  <el-input v-model="ClassesPi.cname" clearable placeholder="请输入班级名称"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindClassesForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
        <el-table :data="pageinfo.list" ref="classesTable" style="width: 100%" @>
        <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="cname" label="班级名称" ></el-table-column>
        <el-table-column label="授课老师名称">
             <template slot-scope="scope">{{ scope.row.teacher1.tname }}</template>
        </el-table-column>
        <el-table-column label="助理老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher2.tname }}</template>
        </el-table-column>
        <el-table-column label="辅导员老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher3.tname }}</template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" prop="cid">
          <template slot-scope="scope">
            <el-button @click="FindByClassesByCid(scope.row.cid)" type="primary" plain icon="el-icon-edit" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table> 
      <el-table-column>
     <el-button @click="DeleteClassesByCidFn" type="danger"  icon="el-icon-delete" >批量删除</el-button>
     </el-table-column>
       <div align="center">
    <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageinfo.pageNum"
          :page-sizes="[2, 3, 5, 10]"
          :page-size="pageinfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageinfo.total">
        </el-pagination>
      </div>
      </div>
    </el-card>
     </div>
    </template>
    <script>
    import { FindClassesForPageNum } from '../../api'
    export default {
    data() {
        return {
            pageinfo:{},
            ClassesPi:{
              pageNum:1,
              pageSize:2,
              cname:'',
            }
        }
    },
    created() {
      this.FindClassesForPageNum()  
    },
    methods: {
        async FindClassesForPageNum() {
            let { data } = await FindClassesForPageNum(this.ClassesPi)
            if(data.code == 1){
                this.pageinfo = data.data
            }
        },
          handleSizeChange(val) {
            this.ClassesPi.pageSize = 1
            this.ClassesPi.pageSize = val
            this.FindClassesForPageNum()
          },
          handleCurrentChange(val) {
            this.ClassesPi.pageNum = val
            this.FindClassesForPageNum()
          }
        }
          
    }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • controller 控制器
    package com.czxy.controller;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import com.czxy.service.ClassesService;
    import com.czxy.vo.BaseResult;
    import com.github.pagehelper.PageInfo;
    
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @RestController
    @RequestMapping("/classes")
    public class ClassesController {
        @Resource
        private ClassesService classesService;
    
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @PostMapping("/addClasses")
        public BaseResult addClasses(@RequestBody Classes classes){
            classesService.addClasses(classes);
            return BaseResult.ok("添加成功");
        }
        
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @return
         */
        @GetMapping("/FindClassesForPageNum")
        public BaseResult FindClassesForPageNum( ClassesPi classesPi){
         PageInfo<Classes> pi =  classesService.FindClassesForPageNum(classesPi);
            for (Classes classes : pi.getList()) {
                System.out.println(classes.toString());
            }
         return BaseResult.ok("查询成功",pi);
        }
    }
    
    
    • service 和 serviceImpl
    package com.czxy.service;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.ClassesPi;
            import com.github.pagehelper.PageInfo;
            import java.util.List;
    
    public interface ClassesService {
        /**
         * 添加班级
         * @param classes
         * @return
         */
        void addClasses(Classes classes);
            /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
    }
    
    
    • mapper 配置类
    package com.czxy.mapper;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import org.apache.ibatis.annotations.*;
    import tk.mybatis.mapper.common.Mapper;
    
    import java.util.List;
    
    public interface ClassesMapper extends Mapper<Classes> {
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        @Select(" <script> select * from tb_class where 1=1 "+
        " <if test = \" classesPi.cname != null and classesPi.cname != '' \"> and cname like #{classesPi.cname} </if> "+
        "</script>")
        @Results(id = "c1",value = {
                @Result(property = "cid",column = "cid"),
                @Result(property = "cname",column = "cname"),
                @Result(property = "teacher1_id",column = "teacher1_id"),
                @Result(property = "teacher2_id",column = "teacher2_id"),
                @Result(property = "teacher3_id",column = "teacher3_id"),
                @Result(property = "teacher1",column = "teacher1_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
                @Result(property = "teacher2",column = "teacher2_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
                @Result(property = "teacher3",column = "teacher3_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID"))
        })
        List<Classes> FindClassesForPageNum(@Param("classesPi") ClassesPi classesPi);
    
    }
    
    

    2.5 功能5:批量删除班级

    在这里插入图片描述

    前段代码

    <template>
     <div>
        <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/classesList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/">班级管理</a></el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/classList">班级列表</a></el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
       <el-card class="box-card">
      <div>
     <div slot="header" >
              <el-form :inline="true" :model="ClassesPi" size="mini" class="demo-form-inline">
                <el-form-item label="班级名称">
                  <el-input v-model="ClassesPi.cname" clearable placeholder="请输入班级名称"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindClassesForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
        <el-table :data="pageinfo.list" ref="classesTable" style="width: 100%" @>
        <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="cname" label="班级名称" ></el-table-column>
        <el-table-column label="授课老师名称">
             <template slot-scope="scope">{{ scope.row.teacher1.tname }}</template>
        </el-table-column>
        <el-table-column label="助理老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher2.tname }}</template>
        </el-table-column>
        <el-table-column label="辅导员老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher3.tname }}</template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" prop="cid">
          <template slot-scope="scope">
            <el-button @click="FindByClassesByCid(scope.row.cid)" type="primary" plain icon="el-icon-edit" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table> 
      <el-table-column>
     <el-button @click="DeleteClassesByCidFn" type="danger"  icon="el-icon-delete" >批量删除</el-button>
     </el-table-column>
       <div align="center">
    <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageinfo.pageNum"
          :page-sizes="[2, 3, 5, 10]"
          :page-size="pageinfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageinfo.total">
        </el-pagination>
        <!-- 修改start -->
        <el-dialog
      title="修改班级"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose">
       <el-form ref="classesFrom" :model="classes" label-width="100px">
            <el-form-item label="班级名称">
                <el-input v-model="classes.cname"></el-input>
            </el-form-item>
            <el-form-item label="授课老师">
                <el-select v-model="classes.teacher1_id" placeholder="请选择授课老师">
                    <el-option v-for="(t1, index1) in teacher1list" :key="index1" :value="t1.tid" :label="t1.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item label="助理老师">
                <el-select v-model="classes.teacher2_id" placeholder="请选择助理老师">
                    <el-option v-for="(t2, index2) in teacher2list" :key="index2" :value="t2.tid" :label="t2.tname"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="辅导员老师">
                <el-select v-model="classes.teacher3_id" placeholder="请选择辅导员老师">
                    <el-option v-for="(t3, index3) in teacher3list" :key="index3" :value="t3.tid" :label="t3.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click.prevent="UpdateClasses">修改班级</el-button>
            </el-form-item>
          </el-form>
    </el-dialog>
         <!-- 修改end -->
      </div>
      </div>
    </el-card>
     </div>
    </template>
    <script>
    import { FindClassesForPageNum,DeleteClassesByCid } from '../../api'
    export default {
    data() {
        return {
            pageinfo:{},
            ClassesPi:{
              pageNum:1,
              pageSize:2,
              cname:'',
            },
            ids:[],
        }
    },
    created() {
      this.FindClassesForPageNum()  
    },
    methods: {
        async FindClassesForPageNum() {
            let { data } = await FindClassesForPageNum(this.ClassesPi)
            if(data.code == 1){
                this.pageinfo = data.data
            }
        },
          handleSizeChange(val) {
            this.ClassesPi.pageSize = 1
            this.ClassesPi.pageSize = val
            this.FindClassesForPageNum()
          },
          handleCurrentChange(val) {
            this.ClassesPi.pageNum = val
            this.FindClassesForPageNum()
          },
           handleClose(done) {
            this.$confirm('确认关闭?')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          },
           DeleteClassesByCidFn(){
            this.ids = this.$refs.classesTable.selection.map(item => item.cid).join(',')
           this.$confirm('确定要删除吗', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async() => {
            let { data } = await DeleteClassesByCid(this.ids)
                  if (data.code == 1) {
                    this.$message.success(data.message)
                    this.ClassesPi.pageNum=1
                    this.FindClassesForPageNum()
                  }
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              })      
            })
          }
          
    }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • controller
    package com.czxy.controller;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import com.czxy.service.ClassesService;
    import com.czxy.vo.BaseResult;
    import com.github.pagehelper.PageInfo;
    import org.springframework.web.bind.annotation.*;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @RestController
    @RequestMapping("/classes")
    public class ClassesController {
        @Resource
        private ClassesService classesService;
    
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @return
         */
        @GetMapping("/FindClassesForPageNum")
        public BaseResult FindClassesForPageNum( ClassesPi classesPi){
         PageInfo<Classes> pi =  classesService.FindClassesForPageNum(classesPi);
            for (Classes classes : pi.getList()) {
                System.out.println(classes.toString());
            }
         return BaseResult.ok("查询成功",pi);
        }
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @PostMapping("/addClasses")
        public BaseResult addClasses(@RequestBody Classes classes){
            classesService.addClasses(classes);
            return BaseResult.ok("添加成功");
        }
    
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        @DeleteMapping("/DeleteClassesByCid/{ids}")
        public BaseResult DeleteClassesByCid(@PathVariable("ids")String ids){
            classesService.DeleteClassesByCid(ids);
            return BaseResult.ok("删除成功");
        }
    
    
    }
    
    
    • service
    package com.czxy.service;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.ClassesPi;
            import com.github.pagehelper.PageInfo;
    
            import java.util.List;
    
    public interface ClassesService {
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
        /**
         * 添加班级
         * @param classes
         * @return
         */
        void addClasses(Classes classes);
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        void DeleteClassesByCid(String ids);
     
    }
    
    
    • serviceImpl
    package com.czxy.service.impl;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.ClassesService;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    import java.util.List;
    @Service
    @Transactional
    public class ClassesServiceImpl implements ClassesService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        @Override
        public PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi) {
            PageHelper.startPage(classesPi.getPageNum(),classesPi.getPageSize());
            if (classesPi.getCname()!=null && !"" .equals(classesPi.getCname())){
                classesPi.setCname("%"+classesPi.getCname()+"%");
            }
            List<Classes> clist =  classesMapper.FindClassesForPageNum(classesPi);
    
            PageInfo<Classes> classesPageInfo = new PageInfo<>(clist);
            return classesPageInfo;
        }
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @Override
        public void addClasses(Classes classes) {
            classesMapper.insertSelective(classes);
        }
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        @Override
        public void DeleteClassesByCid(String ids) {
            String[] split = ids.split(",");
            for (String s : split) {
                classesMapper.deleteByPrimaryKey(Integer.parseInt(s));
            }
        }
    }
    
    

    2.6 功能6:修改班级

    在这里插入图片描述

    前段代码

    <template>
     <div>
        <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/classesList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/">班级管理</a></el-breadcrumb-item>
      <el-breadcrumb-item ><a href="/classList">班级列表</a></el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
       <el-card class="box-card">
      <div>
     <div slot="header" >
              <el-form :inline="true" :model="ClassesPi" size="mini" class="demo-form-inline">
                <el-form-item label="班级名称">
                  <el-input v-model="ClassesPi.cname" clearable placeholder="请输入班级名称"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindClassesForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
        <el-table :data="pageinfo.list" ref="classesTable" style="width: 100%" @>
        <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="cname" label="班级名称" ></el-table-column>
        <el-table-column label="授课老师名称">
             <template slot-scope="scope">{{ scope.row.teacher1.tname }}</template>
        </el-table-column>
        <el-table-column label="助理老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher2.tname }}</template>
        </el-table-column>
        <el-table-column label="辅导员老师名称" >
             <template slot-scope="scope">{{ scope.row.teacher3.tname }}</template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" prop="cid">
          <template slot-scope="scope">
            <el-button @click="FindByClassesByCid(scope.row.cid)" type="primary" plain icon="el-icon-edit" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table> 
      <el-table-column>
     <el-button @click="DeleteClassesByCidFn" type="danger"  icon="el-icon-delete" >批量删除</el-button>
     </el-table-column>
       <div align="center">
    <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageinfo.pageNum"
          :page-sizes="[2, 3, 5, 10]"
          :page-size="pageinfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageinfo.total">
        </el-pagination>
        <!-- 修改start -->
        <el-dialog
      title="修改班级"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose">
       <el-form ref="classesFrom" :model="classes" label-width="100px">
            <el-form-item label="班级名称">
                <el-input v-model="classes.cname"></el-input>
            </el-form-item>
            <el-form-item label="授课老师">
                <el-select v-model="classes.teacher1_id" placeholder="请选择授课老师">
                    <el-option v-for="(t1, index1) in teacher1list" :key="index1" :value="t1.tid" :label="t1.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item label="助理老师">
                <el-select v-model="classes.teacher2_id" placeholder="请选择助理老师">
                    <el-option v-for="(t2, index2) in teacher2list" :key="index2" :value="t2.tid" :label="t2.tname"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="辅导员老师">
                <el-select v-model="classes.teacher3_id" placeholder="请选择辅导员老师">
                    <el-option v-for="(t3, index3) in teacher3list" :key="index3" :value="t3.tid" :label="t3.tname"></el-option>
                 </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click.prevent="UpdateClasses">修改班级</el-button>
            </el-form-item>
          </el-form>
    </el-dialog>
         <!-- 修改end -->
      </div>
      </div>
    </el-card>
     </div>
    </template>
    <script>
    import { FindClassesForPageNum, UpdateClasses,DeleteClassesByCid, FindByClassesByCid,Findteacher1list, Findteacher2list, Findteacher3list,} from '../../api'
    export default {
    data() {
        return {
            pageinfo:{},
            ClassesPi:{
              pageNum:1,
              pageSize:2,
              cname:'',
            },
            ids:[],
            classes:{},
            dialogVisible: false,
            teacher1list:[],
            teacher2list:[],
            teacher3list:[],
            t1:1,
            t2:2,
            t3:3
        }
    },
    created() {
      this.FindClassesForPageNum()  
    },
    methods: {
        async FindClassesForPageNum() {
            let { data } = await FindClassesForPageNum(this.ClassesPi)
            if(data.code == 1){
                this.pageinfo = data.data
            }
        },
          handleSizeChange(val) {
            this.ClassesPi.pageSize = 1
            this.ClassesPi.pageSize = val
            this.FindClassesForPageNum()
          },
          handleCurrentChange(val) {
            this.ClassesPi.pageNum = val
            this.FindClassesForPageNum()
          },
           handleClose(done) {
            this.$confirm('确认关闭?')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          },
           DeleteClassesByCidFn(){
            this.ids = this.$refs.classesTable.selection.map(item => item.cid).join(',')
           this.$confirm('确定要删除吗', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async() => {
            let { data } = await DeleteClassesByCid(this.ids)
                  if (data.code == 1) {
                    this.$message.success(data.message)
                    this.ClassesPi.pageNum=1
                    this.FindClassesForPageNum()
                  }
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              })      
            })
          },
          async FindByClassesByCid(cid){
            this.dialogVisible = true
          let { data: baserest1 } = await Findteacher1list(this.t1)
                this.teacher1list = baserest1.data
    
          let { data: baserest2 } = await Findteacher2list(this.t2)
           this.teacher2list = baserest2.data
    
          let { data:baserest3 } = await Findteacher3list(this.t3)
           this.teacher3list = baserest3.data
    
    
            let { data } = await FindByClassesByCid(cid) 
            if (data.code == 1 ) {
              this.classes = data.data
            }
          }
    }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • controller
    package com.czxy.controller;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import com.czxy.domain.Teacher;
    import com.czxy.service.ClassesService;
    import com.czxy.vo.BaseResult;
    import com.github.pagehelper.PageInfo;
    import org.springframework.web.bind.annotation.*;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @RestController
    @RequestMapping("/classes")
    public class ClassesController {
        @Resource
        private ClassesService classesService;
    
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @return
         */
        @GetMapping("/FindClassesForPageNum")
        public BaseResult FindClassesForPageNum( ClassesPi classesPi){
         PageInfo<Classes> pi =  classesService.FindClassesForPageNum(classesPi);
            for (Classes classes : pi.getList()) {
                System.out.println(classes.toString());
            }
         return BaseResult.ok("查询成功",pi);
        }
    
        /**
         * 查询授课老师信息
         * @param tid
         * @return
         */
        @GetMapping("/Findteacher1list/{t1}")
        public BaseResult Findteacher1list(@PathVariable("t1")Integer tid){
           List<Teacher> tlist =  classesService.Findteacher1list(tid);
            System.out.println(tlist);
           return BaseResult.ok("查询成功",tlist);
        }
        /**
         * 查询助理老师信息
         * @param tid
         * @return
         */
        @GetMapping("/Findteacher2list/{t2}")
        public BaseResult Findteacher2list(@PathVariable("t2")Integer tid){
            List<Teacher> tlist =  classesService.Findteacher2list(tid);
            System.out.println(tlist);
            return BaseResult.ok("查询成功",tlist);
        }
        /**
         * 查询辅导员老师老师信息
         * @param tid
         * @return
         */
        @GetMapping("/Findteacher3list/{t3}")
        public BaseResult Findteacher3list(@PathVariable("t3")Integer tid){
            List<Teacher> tlist =  classesService.Findteacher3list(tid);
            System.out.println(tlist);
            return BaseResult.ok("查询成功",tlist);
        }
    
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @PostMapping("/addClasses")
        public BaseResult addClasses(@RequestBody Classes classes){
            classesService.addClasses(classes);
            return BaseResult.ok("添加成功");
        }
    
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        @DeleteMapping("/DeleteClassesByCid/{ids}")
        public BaseResult DeleteClassesByCid(@PathVariable("ids")String ids){
            classesService.DeleteClassesByCid(ids);
            return BaseResult.ok("删除成功");
        }
    
        /**
         * 修改第一步:回显数据
         * @param cid
         * @return
         */
        @GetMapping("/FindByClassesByCid/{cid}")
        public BaseResult FindByClassesByCid(@PathVariable("cid") Integer cid){
            Classes classes = classesService.FindByClassesByCid(cid);
            return BaseResult.ok("查询成功",classes);
        }
    
    
    }
    
    
    • service
    package com.czxy.service;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.ClassesPi;
            import com.czxy.domain.Teacher;
            import com.github.pagehelper.PageInfo;
    
            import java.util.List;
    
    public interface ClassesService {
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
        /**
         * 查询授课老师信息
         * @param tid
         * @return
         */
        List<Teacher> Findteacher1list(Integer tid);
        /**
         * 查询助理老师信息
         * @param tid
         * @return
         */
        List<Teacher> Findteacher2list(Integer tid);
        /**
         * 查询辅导员老师老师信息
         * @param tid
         * @return
         */
        List<Teacher> Findteacher3list(Integer tid);
        /**
         * 添加班级
         * @param classes
         * @return
         */
        void addClasses(Classes classes);
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        void DeleteClassesByCid(String ids);
        /**
         * 修改第一步:回显数据
         * @param cid
         * @return
         */
        Classes FindByClassesByCid(Integer cid);
    }
    
    • serviceIpml
    package com.czxy.service.impl;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import com.czxy.domain.Teacher;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.ClassesService;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    import java.util.List;
    @Service
    @Transactional
    public class ClassesServiceImpl implements ClassesService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        @Override
        public PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi) {
            PageHelper.startPage(classesPi.getPageNum(),classesPi.getPageSize());
            if (classesPi.getCname()!=null && !"" .equals(classesPi.getCname())){
                classesPi.setCname("%"+classesPi.getCname()+"%");
            }
            List<Classes> clist =  classesMapper.FindClassesForPageNum(classesPi);
    
            PageInfo<Classes> classesPageInfo = new PageInfo<>(clist);
            return classesPageInfo;
        }
        /**
         * 查询授课老师信息
         * @param tid
         * @return
         */
        @Override
        public List<Teacher> Findteacher1list(Integer tid) {
            List<Teacher> tlist =  teacherMapper.Findteacher1list(tid);
            return tlist;
        }
        /**
         * 查询助理老师信息
         * @param tid
         * @return
         */
        @Override
        public List<Teacher> Findteacher2list(Integer tid) {
            List<Teacher> tlist =  teacherMapper.Findteacher1list(tid);
            return tlist;
        }
        /**
         * 查询辅导员老师老师信息
         * @param tid
         * @return
         */
        @Override
        public List<Teacher> Findteacher3list(Integer tid) {
            List<Teacher> tlist =  teacherMapper.Findteacher1list(tid);
            return tlist;
        }
        /**
         * 添加班级
         * @param classes
         * @return
         */
        @Override
        public void addClasses(Classes classes) {
            classesMapper.insertSelective(classes);
        }
        /**
         * 批量删除数据
         * @param ids
         * @return
         */
        @Override
        public void DeleteClassesByCid(String ids) {
            String[] split = ids.split(",");
            for (String s : split) {
                classesMapper.deleteByPrimaryKey(Integer.parseInt(s));
            }
        }
        /**
         * 修改第一步:回显数据
         * @param cid
         * @return
         */
        @Override
        public Classes FindByClassesByCid(Integer cid) {
            Classes classes =  classesMapper.FindByClassesByCid(cid);
            return classes;
        }
    }
    
    
    • mapper
    package com.czxy.mapper;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.ClassesPi;
    import org.apache.ibatis.annotations.*;
    import tk.mybatis.mapper.common.Mapper;
    
    import java.util.List;
    
    public interface ClassesMapper extends Mapper<Classes> {
        /**
         * 查询班级列表(分页+条件)
         * @param
         * @param classesPi
         * @return
         */
        @Select(" <script> select * from tb_class where 1=1 "+
        " <if test = \" classesPi.cname != null and classesPi.cname != '' \"> and cname like #{classesPi.cname} </if> "+
        "</script>")
        @Results(id = "c1",value = {
                @Result(property = "cid",column = "cid"),
                @Result(property = "cname",column = "cname"),
                @Result(property = "teacher1_id",column = "teacher1_id"),
                @Result(property = "teacher2_id",column = "teacher2_id"),
                @Result(property = "teacher3_id",column = "teacher3_id"),
                @Result(property = "teacher1",column = "teacher1_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
                @Result(property = "teacher2",column = "teacher2_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
                @Result(property = "teacher3",column = "teacher3_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID"))
        })
        List<Classes> FindClassesForPageNum(@Param("classesPi") ClassesPi classesPi);
    
        @Select("select * from tb_class where cid=#{cid}")
        @ResultMap( "c1")
        Classes FindByClassesByCid(@Param("cid") Integer cid);
    }
    
    

    2.7 功能7:添加学生

    在这里插入图片描述

    前端代码

    <template>
      <div>
        <el-form ref="form" :model="student" label-width="100px">
            <el-form-item label="选择班级">
              <el-select v-model="student.class_id" placeholder="请选择活班级">
                <el-option v-for="(c, index) in clist" :key="index" :label="c.cname" :value="c.cid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="学生名称">
              <el-input v-model="student.sname"></el-input>
            </el-form-item>
            <el-form-item label="性别">
              <el-radio-group v-model="student.gender">
                <el-radio label="1">男</el-radio>
                <el-radio label="2">女</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="年龄">
              <el-input v-model="student.age"></el-input>
            </el-form-item>
            <el-form-item label="薪资">
              <el-input v-model="student.salary"></el-input>
            </el-form-item>
            <el-form-item label="个人介绍">
              <el-input type="textarea" v-model="student.desc"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="addStudent">添加学生</el-button>
            </el-form-item>
        </el-form>
      </div>
    </template>
    
    <script>
    import { addStudent,Findclasses } from '../../api'
    export default {
      data() {
        return {
          student:{},
          clist:[]
        }
      },
      created() {
        this.Findclasses()
      },
      methods: {
        async Findclasses() {
          let{ data } = await Findclasses();
          if (data.code == 1) {
            this.clist = data.data
          }
        },
        async addStudent() {
           let { data } = await addStudent(this.student)
           if (data.code==1) {
             this.$message.success(data.message)
             this.$router.push('/studentList')
           }
        }
      },
    }
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • domain
    package com.czxy.domain;
    
    import javax.persistence.Column;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import java.io.Serializable;
    @Table(name = "tb_student")
    public class Student implements Serializable {
        @Id
        private Integer sid;
        private String sname;
        private Integer gender;
        private Integer age;
        private Double salary;
        @Column(name = "`desc`")
        private String desc;
        private Integer class_id;
        private Classes classes;
    
        @Override
        public String toString() {
            return "Student{" +
                    "sid=" + sid +
                    ", sname='" + sname + '\'' +
                    ", gender=" + gender +
                    ", age=" + age +
                    ", salary=" + salary +
                    ", desc='" + desc + '\'' +
                    ", class_id=" + class_id +
                    ", classes=" + classes +
                    '}';
        }
    
        public Integer getSid() {
            return sid;
        }
    
        public void setSid(Integer sid) {
            this.sid = sid;
        }
    
        public String getSname() {
            return sname;
        }
    
        public void setSname(String sname) {
            this.sname = sname;
        }
    
        public Integer getGender() {
            return gender;
        }
    
        public void setGender(Integer gender) {
            this.gender = gender;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        public Double getSalary() {
            return salary;
        }
    
        public void setSalary(Double salary) {
            this.salary = salary;
        }
    
        public String getDesc() {
            return desc;
        }
    
        public void setDesc(String desc) {
            this.desc = desc;
        }
    
        public Integer getClass_id() {
            return class_id;
        }
    
        public void setClass_id(Integer class_id) {
            this.class_id = class_id;
        }
    
        public Classes getClasses() {
            return classes;
        }
    
        public void setClasses(Classes classes) {
            this.classes = classes;
        }
    
        public Student(Integer sid, String sname, Integer gender, Integer age, Double salary, String desc, Integer class_id, Classes classes) {
    
            this.sid = sid;
            this.sname = sname;
            this.gender = gender;
            this.age = age;
            this.salary = salary;
            this.desc = desc;
            this.class_id = class_id;
            this.classes = classes;
        }
    
        public Student() {
    
        }
    }
    
    
    • mapper
    package com.czxy.mapper;
    import tk.mybatis.mapper.common.Mapper;
    
    import java.util.List;
    
    public interface StudentMapper extends Mapper<Student> {
     
    }
    
    
    • service
    package com.czxy.service;
    import com.czxy.domain.Student;
    import java.util.List;
    
    public interface StudentService {
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        void addStudent(Student student);
       
    }
    
    
    • serviceImpl
    package com.czxy.service.impl;
    
    
    import com.czxy.domain.Student;
    
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    
    
    @Service
    @Transactional
    public class StudentServiceImpl implements StudentService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @Override
        public void addStudent(Student student) {
            studentMapper.insertSelective(student);
        }
       
    
    
    • controller
    package com.czxy.controller;
    
    
    import com.czxy.domain.Student;
    
    import com.czxy.service.StudentService;
    import com.czxy.vo.BaseResult;
    
    import org.springframework.web.bind.annotation.*;
    
    import javax.annotation.Resource;
    
    
    @RestController
    @RequestMapping("/student")
    public class StudentController {
        @Resource
        private StudentService studentService;
    
    
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @PostMapping("/addStudent")
        private BaseResult addStudent(@RequestBody Student student){
            studentService.addStudent(student);
            return BaseResult.ok("添加成功");
        }
    
    
    }
    
    

    2.8 功能8:学生列表(基本列表+分页+条件)

    在这里插入图片描述

    前端代码

    <template>
      <div>
        <div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/studentList' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/studentList">学生管理</a></el-breadcrumb-item>
                <el-breadcrumb-item>学生列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
    
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                   <div slot="header" >
              <el-form :inline="true" :model="studentPi" size="mini" class="demo-form-inline">
                <el-form-item label="姓名">
                  <el-input v-model="studentPi.sname" clearable placeholder="请输入学生姓名"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-radio-group v-model="studentPi.gender">
                    <el-radio label="1">男</el-radio>
                    <el-radio label="2">女</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="薪资">
                    <el-col :span="10">
                    <el-form-item>
                        <el-input  placeholder="请输入起始值" v-model="studentPi.minsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                    <el-col class="line" :span="2">-</el-col>
                    <el-col :span="10">
                    <el-form-item >
                        <el-input placeholder="请输入结束值" v-model="studentPi.maxsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindStudentListForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
            </div>
            <div>
                <el-table ref="studentTable" :data="pageinfo.list" style="width: 100%">
                    <el-table-column  type="selection" width="55"></el-table-column>
                    <el-table-column prop="sname" label="学生姓名"></el-table-column>
                    <el-table-column label="性别">
                        <template scope="scope">
                            {{scope.row.gender==1 ? "男":"女"}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="age" label="年龄"></el-table-column>
                    <el-table-column prop="salary" label="薪资"></el-table-column>
                    <el-table-column label="班级名称">
                    <template slot-scope="scope">{{ scope.row.classes.cname }}</template>
                    </el-table-column>
                    <el-table-column label="授课老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher1.tname }}</template>
                    </el-table-column>
                    <el-table-column label="助理老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher2.tname }}</template>
                    </el-table-column>
                    <el-table-column label="辅导员老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher3.tname }}</template>
                    </el-table-column>
                    <el-table-column prop="sid" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="FindStudent(scope.row.sid)" type="text" size="small">查看</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <el-table-column>
                    <el-button @click="deleteStudentBysid" type="danger" >批量删除</el-button>
                </el-table-column>
                <div align ="center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageinfo.pageNum"
                        :page-sizes="[2, 3, 5, 10]"
                        :page-size="pageinfo.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageinfo.total">
                    </el-pagination>
                </div>
            </div>
        </el-card>
      </div>
    </template>
    
    <script>
    import {FindStudentListForPageNum } from '../../api'
    export default {
      data() {
          return {
            pageinfo:{},
            studentPi:{
                pageNum:1,
                pageSize:2,
                sname:'',
                gender:'',
                minsalary:'',
                maxsalary:''
            },
          }
      },
      created() {
          this.FindStudentListForPageNum()
      },
      methods: {
          async FindStudentListForPageNum(){
              let { data } = await FindStudentListForPageNum(this.studentPi)
              if (data.code == 1) {
                  this.pageinfo = data.data
              }
          },
           handleSizeChange(val) {
            this.studentPi.pageNum = 1
            this.studentPi.pageSize = val
            this.FindStudentListForPageNum()
          },
          handleCurrentChange(val) {
           this.studentPi.pageNum =val
           this.FindStudentListForPageNum()
          }
      }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    package com.czxy.controller;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.Student;
            import com.czxy.domain.StudentPi;
            import com.czxy.service.StudentService;
            import com.czxy.vo.BaseResult;
            import com.github.pagehelper.PageInfo;
            import org.springframework.web.bind.annotation.*;
    
            import javax.annotation.Resource;
            import java.util.List;
    
    @RestController
    @RequestMapping("/student")
    public class StudentController {
        @Resource
        private StudentService studentService;
    
        /**
         *  学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @GetMapping("/FindStudentListForPageNum")
        public BaseResult FindStudentListForPageNum( StudentPi studentPi){
            PageInfo<Student> pageInfo =  studentService.FindStudentListForPageNum(studentPi);
            return BaseResult.ok("查询成功",pageInfo);
        }
    
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @PostMapping("/addStudent")
        private BaseResult addStudent(@RequestBody Student student){
            studentService.addStudent(student);
            return BaseResult.ok("添加成功");
        }
    }
    
    
    • service
    package com.czxy.service;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.github.pagehelper.PageInfo;
    
    import java.util.List;
    
    public interface StudentService {
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        void addStudent(Student student);
    
    }
    
    
    • serviceImpl
    package com.czxy.service.impl;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.StudentService;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @Service
    @Transactional
    public class StudentServiceImpl implements StudentService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @Override
        public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
            PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
        //    设置姓名
            if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
                studentPi.setSname("%"+studentPi.getSname()+"%");
            }
            List<Student> slist =  studentMapper.FindStudentListForPageNum(studentPi);
            PageInfo<Student> pageInfo = new PageInfo<>(slist);
            return pageInfo;
        }
    
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @Override
        public void addStudent(Student student) {
            studentMapper.insertSelective(student);
        }
     
    
    
    • mapper
    package com.czxy.mapper;
    
            import com.czxy.domain.Student;
            import com.czxy.domain.StudentPi;
            import org.apache.ibatis.annotations.*;
            import tk.mybatis.mapper.common.Mapper;
    
            import java.util.List;
    
    public interface StudentMapper extends Mapper<Student> {
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @Select("<script> select * from tb_student where 1=1"+
                "<if test= \" studentPi.sname != null and studentPi.sname != '' \"> and sname like #{studentPi.sname} </if> "+
                "<if test= \" studentPi.gender != null and studentPi.gender != '' \"> and gender=#{studentPi.gender} </if>"+
                "<if test= \" studentPi.minsalary != null and studentPi.minsalary != '' and studentPi.maxsalary != null and studentPi.maxsalary != '' \"> and salary between #{studentPi.minsalary} and #{studentPi.maxsalary} </if>"+
                "</script>")
        @Results(id = "s1",value = {
                @Result(property = "class_id",column = "class_id"),
                @Result(property = "classes",column = "class_id",one = @One(select = "com.czxy.mapper.ClassesMapper.FindByClassesByCid"))
        })
        List<Student> FindStudentListForPageNum(@Param("studentPi") StudentPi studentPi);
    
    
    }
    
    

    2.9 功能9:批量删除

    在这里插入图片描述

    前段代码

    <template>
      <div>
        <div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/studentList' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/studentList">学生管理</a></el-breadcrumb-item>
                <el-breadcrumb-item>学生列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
    
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                   <div slot="header" >
              <el-form :inline="true" :model="studentPi" size="mini" class="demo-form-inline">
                <el-form-item label="姓名">
                  <el-input v-model="studentPi.sname" clearable placeholder="请输入学生姓名"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-radio-group v-model="studentPi.gender">
                    <el-radio label="1">男</el-radio>
                    <el-radio label="2">女</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="薪资">
                    <el-col :span="10">
                    <el-form-item>
                        <el-input  placeholder="请输入起始值" v-model="studentPi.minsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                    <el-col class="line" :span="2">-</el-col>
                    <el-col :span="10">
                    <el-form-item >
                        <el-input placeholder="请输入结束值" v-model="studentPi.maxsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindStudentListForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
            </div>
            <div>
                <el-table ref="studentTable" :data="pageinfo.list" style="width: 100%">
                    <el-table-column  type="selection" width="55"></el-table-column>
                    <el-table-column prop="sname" label="学生姓名"></el-table-column>
                    <el-table-column label="性别">
                        <template scope="scope">
                            {{scope.row.gender==1 ? "男":"女"}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="age" label="年龄"></el-table-column>
                    <el-table-column prop="salary" label="薪资"></el-table-column>
                    <el-table-column label="班级名称">
                    <template slot-scope="scope">{{ scope.row.classes.cname }}</template>
                    </el-table-column>
                    <el-table-column label="授课老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher1.tname }}</template>
                    </el-table-column>
                    <el-table-column label="助理老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher2.tname }}</template>
                    </el-table-column>
                    <el-table-column label="辅导员老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher3.tname }}</template>
                    </el-table-column>
                    <el-table-column prop="sid" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="FindStudent(scope.row.sid)" type="text" size="small">查看</el-button>
                    </template>
                    </el-table-column>
                </el-table>
             
                <el-table-column>
                    <el-button @click="deleteStudentBysid" type="danger" >批量删除</el-button>
                </el-table-column>
                <div align ="center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageinfo.pageNum"
                        :page-sizes="[2, 3, 5, 10]"
                        :page-size="pageinfo.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageinfo.total">
                    </el-pagination>
                </div>
            </div>
        </el-card>
      </div>
    </template>
    
    <script>
    import {FindStudentListForPageNum,deleteStudentBysid } from '../../api'
    export default {
      data() {
          return {
            pageinfo:{},
            studentPi:{
                pageNum:1,
                pageSize:2,
                sname:'',
                gender:'',
                minsalary:'',
                maxsalary:''
            },
            ids:[]
        
          }
      },
      created() {
          this.FindStudentListForPageNum()
          this.Findclasses()
      },
      methods: {
          async FindStudentListForPageNum(){
              let { data } = await FindStudentListForPageNum(this.studentPi)
              if (data.code == 1) {
                  this.pageinfo = data.data
              }
          },
           handleSizeChange(val) {
            this.studentPi.pageSize = 1
            this.studentPi.pageSize = val
            this.FindStudentListForPageNum()
          },
          handleCurrentChange(val) {
           this.studentPi.pageNum =val
           this.FindStudentListForPageNum()
          },
           deleteStudentBysid() {
               this.ids = this.$refs.studentTable.selection.map(item => item.sid).join(',')
               this.$confirm('确认要删除吗?').then(async() =>{
                   let { data } = await deleteStudentBysid(this.ids)
                   if (data.code == 1) {
                       this.$message.success(data.message)
                       this.studentPi.pageNum=1
                       this.FindStudentListForPageNum()
                   }
               })
               .catch(()=>{
                   this.$message.info("取消删除")
                   this.FindStudentListForPageNum()
               })
          },
           handleClose(done) {
            this.$confirm('确认关闭?')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          }
        }
      }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • controller
    package com.czxy.controller;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.Student;
            import com.czxy.domain.StudentPi;
            import com.czxy.service.StudentService;
            import com.czxy.vo.BaseResult;
            import com.github.pagehelper.PageInfo;
            import org.springframework.web.bind.annotation.*;
    
            import javax.annotation.Resource;
            import java.util.List;
    
    @RestController
    @RequestMapping("/student")
    public class StudentController {
        @Resource
        private StudentService studentService;
    
        /**
         *  学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @GetMapping("/FindStudentListForPageNum")
        public BaseResult FindStudentListForPageNum( StudentPi studentPi){
            PageInfo<Student> pageInfo =  studentService.FindStudentListForPageNum(studentPi);
            return BaseResult.ok("查询成功",pageInfo);
        }
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @PostMapping("/addStudent")
        private BaseResult addStudent(@RequestBody Student student){
            studentService.addStudent(student);
            return BaseResult.ok("添加成功");
        }
    
        /**
         *  批量删除
         * @param ids
         * @return
         */
        @DeleteMapping("/deleteStudentBysid/{ids}")
        public BaseResult deleteStudentBysid(@PathVariable("ids") String ids){
            studentService.deleteStudentBysid(ids);
            return BaseResult.ok("删除成功");
        }
    
     
    
    }
    
    
    • service
    package com.czxy.service;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.github.pagehelper.PageInfo;
    
    import java.util.List;
    
    public interface StudentService {
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
    
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        void addStudent(Student student);
        /**
         *  批量删除
         * @param ids
         * @return
         */
        void deleteStudentBysid(String ids);
    
    }
    
    
    • serviceImpl
    package com.czxy.service.impl;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.StudentService;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @Service
    @Transactional
    public class StudentServiceImpl implements StudentService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @Override
        public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
            PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
        //    设置姓名
            if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
                studentPi.setSname("%"+studentPi.getSname()+"%");
            }
            List<Student> slist =  studentMapper.FindStudentListForPageNum(studentPi);
            PageInfo<Student> pageInfo = new PageInfo<>(slist);
            return pageInfo;
        }
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @Override
        public void addStudent(Student student) {
            studentMapper.insertSelective(student);
        }
        /**
         *  批量删除
         * @param ids
         * @return
         */
        @Override
        public void deleteStudentBysid(String ids) {
            String[] split = ids.split(",");
            for (String s : split) {
                studentMapper.deleteByPrimaryKey(Integer.parseInt(s));
            }
        }
     
    
    

    2.10 功能10:修改学生

    在这里插入图片描述

    前端代码

    <template>
      <div>
        <div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/studentList' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/studentList">学生管理</a></el-breadcrumb-item>
                <el-breadcrumb-item>学生列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
    
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                   <div slot="header" >
              <el-form :inline="true" :model="studentPi" size="mini" class="demo-form-inline">
                <el-form-item label="姓名">
                  <el-input v-model="studentPi.sname" clearable placeholder="请输入学生姓名"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-radio-group v-model="studentPi.gender">
                    <el-radio label="1">男</el-radio>
                    <el-radio label="2">女</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="薪资">
                    <el-col :span="10">
                    <el-form-item>
                        <el-input  placeholder="请输入起始值" v-model="studentPi.minsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                    <el-col class="line" :span="2">-</el-col>
                    <el-col :span="10">
                    <el-form-item >
                        <el-input placeholder="请输入结束值" v-model="studentPi.maxsalary" ></el-input>
                    </el-form-item>
                    </el-col>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="FindStudentListForPageNum">查询</el-button>
                </el-form-item>
              </el-form>
        </div>
            </div>
            <div>
                <el-table ref="studentTable" :data="pageinfo.list" style="width: 100%">
                    <el-table-column  type="selection" width="55"></el-table-column>
                    <el-table-column prop="sname" label="学生姓名"></el-table-column>
                    <el-table-column label="性别">
                        <template scope="scope">
                            {{scope.row.gender==1 ? "男":"女"}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="age" label="年龄"></el-table-column>
                    <el-table-column prop="salary" label="薪资"></el-table-column>
                    <el-table-column label="班级名称">
                    <template slot-scope="scope">{{ scope.row.classes.cname }}</template>
                    </el-table-column>
                    <el-table-column label="授课老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher1.tname }}</template>
                    </el-table-column>
                    <el-table-column label="助理老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher2.tname }}</template>
                    </el-table-column>
                    <el-table-column label="辅导员老师">
                    <template slot-scope="scope">{{ scope.row.classes.teacher3.tname }}</template>
                    </el-table-column>
                    <el-table-column prop="sid" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="FindStudent(scope.row.sid)" type="text" size="small">查看</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <el-dialog
                    title="修改学生"
                    :visible.sync="dialogVisible"
                    width="50%"
                    :before-close="handleClose">
                       <el-form ref="form" :model="student" label-width="100px">
            <el-form-item label="选择班级">
              <el-select v-model="student.class_id" placeholder="请选择活班级">
                <el-option v-for="(c, index) in clist" :key="index" :label="c.cname" :value="c.cid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="学生名称">
              <el-input v-model="student.sname"></el-input>
            </el-form-item>
            <el-form-item label="性别">
              <el-radio-group v-model="student.gender">
                <el-radio :label="1">男</el-radio>
                <el-radio :label="2">女</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="年龄">
              <el-input v-model="student.age"></el-input>
            </el-form-item>
            <el-form-item label="薪资">
              <el-input v-model="student.salary"></el-input>
            </el-form-item>
            <el-form-item label="个人介绍">
              <el-input type="textarea" v-model="student.desc"></el-input>
            </el-form-item>
            <el-form-item>
                 <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary">确 定</el-button>
            </el-form-item>
        </el-form>
                </el-dialog>
                <el-table-column>
                    <el-button @click="deleteStudentBysid" type="danger" >批量删除</el-button>
                </el-table-column>
                <div align ="center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageinfo.pageNum"
                        :page-sizes="[2, 3, 5, 10]"
                        :page-size="pageinfo.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageinfo.total">
                    </el-pagination>
                </div>
            </div>
        </el-card>
      </div>
    </template>
    
    <script>
    import {FindStudentListForPageNum, Findclasses,deleteStudentBysid ,FindStudent} from '../../api'
    export default {
      data() {
          return {
            pageinfo:{},
            studentPi:{
                pageNum:1,
                pageSize:2,
                sname:'',
                gender:'',
                minsalary:'',
                maxsalary:''
            },
            ids:[],
            student:{},
            clist:[],
            dialogVisible:false
          }
      },
      created() {
          this.FindStudentListForPageNum()
          this.Findclasses()
      },
      methods: {
          async FindStudentListForPageNum(){
              let { data } = await FindStudentListForPageNum(this.studentPi)
              if (data.code == 1) {
                  this.pageinfo = data.data
              }
          },
           handleSizeChange(val) {
            this.studentPi.pageSize = 1
            this.studentPi.pageSize = val
            this.FindStudentListForPageNum()
          },
          handleCurrentChange(val) {
           this.studentPi.pageNum =val
           this.FindStudentListForPageNum()
          },
           deleteStudentBysid() {
               this.ids = this.$refs.studentTable.selection.map(item => item.sid).join(',')
               this.$confirm('确认要删除吗?').then(async() =>{
                   let { data } = await deleteStudentBysid(this.ids)
                   if (data.code == 1) {
                       this.$message.success(data.message)
                       this.studentPi.pageNum=1
                       this.FindStudentListForPageNum()
                   }
               })
               .catch(()=>{
                   this.$message.info("取消删除")
                   this.FindStudentListForPageNum()
               })
          },
          async Findclasses (){
        let { data:baserest1 }  = await Findclasses()
            if (baserest1.code == 1) {
                this.clist = baserest1.data
            }
          },
         async FindStudent(sid) {
            this.dialogVisible = true
        
            let { data:baserest2 } = await FindStudent(sid)
            if (baserest2.code==1) {
                this.student = baserest2.data
            }
          },
           handleClose(done) {
            this.$confirm('确认关闭?')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          }
        }
      }
    
    </script>
    
    <style>
    
    </style>
    

    后端代码

    • controller
    package com.czxy.controller;
    
            import com.czxy.domain.Classes;
            import com.czxy.domain.Student;
            import com.czxy.domain.StudentPi;
            import com.czxy.service.StudentService;
            import com.czxy.vo.BaseResult;
            import com.github.pagehelper.PageInfo;
            import org.springframework.web.bind.annotation.*;
    
            import javax.annotation.Resource;
            import java.util.List;
    
    @RestController
    @RequestMapping("/student")
    public class StudentController {
        @Resource
        private StudentService studentService;
    
        /**
         *  学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @GetMapping("/FindStudentListForPageNum")
        public BaseResult FindStudentListForPageNum( StudentPi studentPi){
            PageInfo<Student> pageInfo =  studentService.FindStudentListForPageNum(studentPi);
            return BaseResult.ok("查询成功",pageInfo);
        }
    
        /**
         *  查询班级信息
         * @return
         */
        @GetMapping("/Findclasses")
        public BaseResult Findclasses(){
            List<Classes> clist = studentService.Findclasses();
            return BaseResult.ok("查询成功",clist);
        }
    
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @PostMapping("/addStudent")
        private BaseResult addStudent(@RequestBody Student student){
            studentService.addStudent(student);
            return BaseResult.ok("添加成功");
        }
    
        /**
         *  批量删除
         * @param ids
         * @return
         */
        @DeleteMapping("/deleteStudentBysid/{ids}")
        public BaseResult deleteStudentBysid(@PathVariable("ids") String ids){
            studentService.deleteStudentBysid(ids);
            return BaseResult.ok("删除成功");
        }
    
        /**
         *  修改第一步: 回显对象
         * @param sid
         * @return
         */
        @GetMapping("/FindStudent/{sid}")
        public BaseResult FindStudent(@PathVariable("sid") Integer sid){
            Student student =  studentService.FindStudent(sid);
            return BaseResult.ok("查询成功",student);
        }
    
    
    }
    
    
    • service
    package com.czxy.service;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.github.pagehelper.PageInfo;
    
    import java.util.List;
    
    public interface StudentService {
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
        /**
         * 查询班级信息
         * @return
         */
        List<Classes> Findclasses();
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        void addStudent(Student student);
        /**
         *  批量删除
         * @param ids
         * @return
         */
        void deleteStudentBysid(String ids);
        /**
         *  修改第一步: 回显对象
         * @param sid
         * @return
         */
        Student FindStudent(Integer sid);
    }
    
    
    • serviceImpl
    package com.czxy.service.impl;
    
    import com.czxy.domain.Classes;
    import com.czxy.domain.Student;
    import com.czxy.domain.StudentPi;
    import com.czxy.mapper.ClassesMapper;
    import com.czxy.mapper.StudentMapper;
    import com.czxy.mapper.TeacherMapper;
    import com.czxy.service.StudentService;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @Service
    @Transactional
    public class StudentServiceImpl implements StudentService {
        @Resource
        private ClassesMapper classesMapper;
        @Resource
        private TeacherMapper teacherMapper;
        @Resource
        private StudentMapper studentMapper;
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @Override
        public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
            PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
        //    设置姓名
            if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
                studentPi.setSname("%"+studentPi.getSname()+"%");
            }
            List<Student> slist =  studentMapper.FindStudentListForPageNum(studentPi);
            PageInfo<Student> pageInfo = new PageInfo<>(slist);
            return pageInfo;
        }
        /**
         * 查询班级信息
         * @return
         */
        @Override
        public List<Classes> Findclasses() {
            List<Classes> classes = classesMapper.selectAll();
            return classes;
        }
        /**
         *  添加一个学生
         * @param student
         * @return
         */
        @Override
        public void addStudent(Student student) {
            studentMapper.insertSelective(student);
        }
        /**
         *  批量删除
         * @param ids
         * @return
         */
        @Override
        public void deleteStudentBysid(String ids) {
            String[] split = ids.split(",");
            for (String s : split) {
                studentMapper.deleteByPrimaryKey(Integer.parseInt(s));
            }
        }
        /**
         *  修改第一步: 回显对象
         * @param sid
         * @return
         */
        @Override
        public Student FindStudent(Integer sid) {
           Student student =  studentMapper.FindStudent(sid);
           return student;
        }
    }
    
    
    • mapper
    package com.czxy.mapper;
    
            import com.czxy.domain.Student;
            import com.czxy.domain.StudentPi;
            import org.apache.ibatis.annotations.*;
            import tk.mybatis.mapper.common.Mapper;
    
            import java.util.List;
    
    public interface StudentMapper extends Mapper<Student> {
        /**
         * 学生列表(分页+多条件)
         * @param studentPi
         * @return
         */
        @Select("<script> select * from tb_student where 1=1"+
                "<if test= \" studentPi.sname != null and studentPi.sname != '' \"> and sname like #{studentPi.sname} </if> "+
                "<if test= \" studentPi.gender != null and studentPi.gender != '' \"> and gender=#{studentPi.gender} </if>"+
                "<if test= \" studentPi.minsalary != null and studentPi.minsalary != '' and studentPi.maxsalary != null and studentPi.maxsalary != '' \"> and salary between #{studentPi.minsalary} and #{studentPi.maxsalary} </if>"+
                "</script>")
        @Results(id = "s1",value = {
                @Result(property = "class_id",column = "class_id"),
                @Result(property = "classes",column = "class_id",one = @One(select = "com.czxy.mapper.ClassesMapper.FindByClassesByCid"))
        })
        List<Student> FindStudentListForPageNum(@Param("studentPi") StudentPi studentPi);
    
        @Select("select * from tb_student where sid=#{sid}")
        @ResultMap("s1")
        Student FindStudent(@Param("sid") Integer sid);
    }
    
    
    展开全文
  • 1、MyBatis与Spring的整合 MyBatis是一款优秀的ORM框架。Spring是一款集控制反转、依赖注入与切面编程于一身的Java框架。下面将介绍MyBatis与Spring的整合。 1.1 下载依赖的jar包 (1)MyBatis框架相关的jar包 ...
  • 准备工作: 1.pom.xml导入需要的依赖jar包. 2.数据库添加账户表. 3.jdbc配置文件. ...jdbc.url=jdbc:mysql://127.0.0.1:3306/ssm_db?useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=...
  • 如今时代,越来越看不懂,创业者叫CEO不叫老板,很高大上,不再睡地板了,到处吹牛逼,动不动就整合资源,作为老一辈吃过苦耐过劳睡过地板的满脸沧桑满肚唠叨的IT创业者,我很是忧虑,也感觉到自已内心的彷徨,...
  • Spring及三大框架整合

    千次阅读 2017-10-26 16:42:07
    课堂笔记 Spring概述 Spring介绍  Spring它是一个一站式的分层轻量级框架。 Spring体系结构    1. core container a) beans与core 它们提供spring框架最基本功能,包含ioc与di ...c) 
  • 系统架构改进--多系统用户整合

    千次阅读 2017-12-12 11:16:31
    单WEB应用登录登出实现原理首先,我们来分析下单Web应用系统登录登出的实现机理。 Web系统登录登出功能,通常属于系统安全管理模块的一部分。登录,意味着用户与系统之间的一次会话开始,登出,意味着本次会话的...
  • SpringBoot 整合Activiti(一)

    万次阅读 热门讨论 2018-01-16 15:35:23
    最近在学习Activiti工作流,学习过程整理下,方便以后回顾。 我这里用的Activiti版本是5.22,考虑后面应该会做在线绘制流程图,而6.0版本网上信息过少。。。(如下配置6.0也可试用) ... 项目目录结构如下:
  • SpringBoot整合Elasticsearch

    万次阅读 多人点赞 2020-04-19 00:33:11
    1 SpringBoot整合Spring Data Elasticsearch Elasticsearch提供的Java客户端有一些不太方便的地方: 很多地方需要拼接Json字符串,在java中拼接字符串有多恐怖你应该懂的 需要自己把对象序列化为json存储 查询...
  • 应该是跟VDP有关,可能是由隐藏的快照之类的。 解决办法:新生成快照后再删除或者是克隆一下再删除,可以去除这个告警。
  • 分享一个强大资源网站整合

    万次阅读 2018-11-26 21:29:26
    https://blog.csdn.net/qq_38354073/article/details/84438184
  • SpringMVC、Spring、Mybatis整合开发,包含了PPT进行讲解和实例展示如何进行整合开发,快速上手SSM框架,能进行一般的业务逻辑的开发,希望此项目可以帮助你进行学习
  • 下载加我2691784946QQ
  • 数据整合(Data Consolidation) 数据整合(Data Consolidation)的概念数据整合是把在不同数据源的数据收集、整理、清洗,转换后(有点像ETL)加载到一个新的数据源,为数据消费者提供统一数据视图的数据集成方式...
  • SpringBoot整合Hbase

    万次阅读 2020-05-14 17:39:30
    接下来是用Spring整合Hbase的实际案例,且在最后会给出整合中可能会出现的问题,以及解决方案。这里我是用本地Windows的IDEA,与局域网的伪分布Hbase集群做的连接,其中Hbase集群包括的组件有:Jdk1.8、Hadoop2.7.6...
  • 转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:...Spring2.5+Struts2+Jpa的整合跟Spring2.5+Struts1.3.8+Jpa的整合过程非常相似:第1步:Spring2.5+Jpa进行整合。第2步:在整合完毕的Spring2.5+Jpa的基础上进
  • Spring和ActiveMQ的整合实例源码

    千次下载 热门讨论 2020-07-30 23:32:18
    此实例基于Spring+JMS+ActiveMQ+Tomcat,注解的完整实例,包含jar包
  • Struts2整合Spring的两种方式(最新)

    千次阅读 2017-08-07 01:12:29
    方式一只需要在项目中引入struts2-spring-plugin-2.2.1.1.jar这个Jar包就可以了。这个Jar包引入之后确保web.xml中加载了spring配置,否则会报空指针异常(原因是方式一会自动在spring配置文件中找action依赖的...
1 2 3 4 5 ... 20
收藏数 767,241
精华内容 306,896
关键字:

整合