杨校老师课堂之就业信息平台

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 杨校老师课堂之就业信息平台

1. 创建maven项目

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

 <groupId>cn.javabs</groupId>
    <artifactId>job</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <name>job</name>
    <description>Demo project for Spring Boot</description>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!--模板引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--SpringMVC的jar包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--springboot启动器-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>
        <!--热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope><!--运行时期-->
            <optional>true</optional>
        </dependency>
        <!--MySQL数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--Lombok简化实体类的插件包-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!--SpringBoot启动的测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--单元测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!--数据源连接池:德鲁伊-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.6</version>
        </dependency>
        <!--mail-->
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.1</version>
        </dependency>
        <!--上传-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <!--分页的插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>
    </dependencies>
2. 编写配置文件
# 服务器
server.port=8081

#json的时间格式:
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

#模板引擎
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8

# 静态资源的释放
spring.mvc.static-path-pattern=/static/**

#文件上传的大小
spring.servlet.multipart.max-file-size=2MB

# 定义 加载 开发环境下的  配置文件
#spring.profiles.active=dev

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/job?useUnicode=true&characterEncoding=utf-8&serverTimeZone=GMT
spring.datasource.username=root
spring.datasource.password=sorry

mybatis.mapper-locations=classpath:/cn/javabs/job/mapper/*.xml

#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

pagehelper.pageSize = 10

#热部署
spring.devtools.restart.enabled=true

3. 编写实体类
package cn.javabs.job.entity;

import lombok.Data;

/**
 * 用户实体类设计
 *  1. 应聘者:  学生
 *  2. 招聘者:  公司人力资源 
 */
@Data
public class User {

    //    -----------------定义常量:--------------------
    
    final int  USER_SEX_MAN = 1;    // 性别  男
    final int  USER_SEX_WOMAN = 2;  // 性别  女
    final int  USER_SEX_UNKONW = 0; // 性别  未知
    final  String  DEFAULT_HEAD_IMGAE = "common/default_img.jpg"; // 默认的用户头像
    final  String  DEFAULT_WORK_EXP = "应届毕业生"; // 默认是应届毕业生
    final  String  DEFAULT_DEGREE = "其他"; // 默认是其他、专科、本科、研究生

//    -----------------变量:--------------------

    private int userId;

    private String username; // 用户名
    
    private String password;// 密码
    
    private String email;// 邮箱地址
  
    private String headPic = DEFAULT_HEAD_IMGAE; // 用户头像
  
    private String workExp = DEFAULT_WORK_EXP;  // 工作经验,默认是应届毕业生
 
    private String degree = DEFAULT_DEGREE;   // 学历,默认是其他

    private int sex = USER_SEX_UNKONW ;// 用户性别 默认是未知
  
    private int type ;  // 用户类别, 0-学生(应聘者);1-(公司的HR)招聘者
  
    private String mobile ;  // 手机号码

    private String selfDescription ;  // 自我描述

}
4. 编写数据持久层接口
package cn.javabs.job.mapper;

import cn.javabs.job.entity.User;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("userMapper")
public interface UserMapper {

    /**
     * 后端获取所有用户的信息
     * @return 返回的集合
     */
   List<User> findAllUserList();

    /**
     * 按照邮箱查询用户的信息
     * @param email
     * @return 返回的对象
     */
    User findUserByEmail(String email);

    /**
     * 按照条件(用户名或者性别或者学历)查询用户信息   返回的集合
     * @param condition
     * @return
     */
    List<User> findUserByCondition(String condition);

    /**
     * 按照用户id查询用户信息
     * @param userId
     * @return  返回的对象
     */
    User findUserByUserId(int userId);
    
    /**
     * 用户登录
     *  根据用户名和密码及用户类型执行 登录
     * @param user
     * @return
     */
    User login(User user);

    int addUser(User user);
    
    int delUser(int userId);
    
    int editUser(User user);

}
5. 编写持久层映射文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "
                        http://mybatis.org/dtd/mybatis-3-mapper.dtd" >


<mapper namespace="cn.javabs.job.mapper.UserMapper">

    <!--添加用户-->
    <insert id="addUser" parameterType="cn.javabs.job.entity.User">
        insert into user
        <trim prefix="(" suffix=") values" suffixOverrides=",">
            <if test="username != nul and username != '' ">
                username,
            </if>
            <if test="password != nul and password != '' ">
                password,
            </if>
            <if test="headPic != nul and headPic != '' ">
                 headPic,
            </if>
            <if test="sex != nul and sex != '' ">
                    sex,
            </if>
            <if test="email != nul and email != '' ">
                    email,
            </if>
            <if test="mobile != nul and mobile != '' ">
                    mobile,
            </if>
            <if test="degree != nul and degree != '' ">
                    degree,
            </if>
            <if test="workExp != nul and workExp != '' ">
                    workExp,
            </if>
            <if test="type != nul and type != '' ">
                    type,
            </if>
            <if test="selfDescription != nul and selfDescription != '' ">
                    selfDescription,
            </if>

        </trim>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != nul and username != '' ">
                #{username},
            </if>
            <if test="password != nul and password != '' ">
                #{password},
            </if>
            <if test="headPic != nul and headPic != '' ">
                #{headPic},
            </if>
            <if test="sex != nul and sex != '' ">
                #{sex},
            </if>
            <if test="email != nul and email != '' ">
                #{email},
            </if>
            <if test="mobile != nul and mobile != '' ">
                #{mobile},
            </if>
            <if test="degree != nul and degree != '' ">
                #{degree},
            </if>
            <if test="workExp != nul and workExp != '' ">
                #{workExp},
            </if>
            <if test="type != nul and type != '' ">
                #{type},
            </if>
            <if test="selfDescription != nul and selfDescription != '' ">
                #{selfDescription},
            </if>

        </trim>

    </insert>

    <!--修改用户-->
    <update id="editUser" parameterType="cn.javabs.job.entity.User">
        update user
        <set>
           <!-- <if test="username != nul and username != '' ">
                #{username},
            </if>-->
            <if test="password != nul and password != '' ">
                #{password},
            </if>
            <if test="headPic != nul and headPic != '' ">
                #{headPic},
            </if>
            <if test="sex != nul and sex != '' ">
                #{sex},
            </if>
            <if test="email != nul and email != '' ">
                #{email},
            </if>
            <if test="mobile != nul and mobile != '' ">
                #{mobile},
            </if>
            <if test="degree != nul and degree != '' ">
                #{degree},
            </if>
            <if test="workExp != nul and workExp != '' ">
                #{workExp},
            </if>
          <!--  <if test="type != nul and type != '' ">
                #{type},
            </if>-->
            <if test="selfDescription != nul and selfDescription != '' ">
                #{selfDescription},
            </if>
        </set>
            where
             userId = #{userId}
    </update>

    <!--删除用户-->
    <delete id="delUser" parameterType="int">
        delete  from user
        <where>
            <if test="userId != nul and userId != '' ">
               and userId =  #{userId},
            </if>
        </where>
    </delete>

    <!--查询所有用户-->
    <select id="findAllUserList" resultType="cn.javabs.job.entity.User">
        select * from  user
    </select>

    <!--按照邮箱查询用户的信息-->
    <select id="findUserByEmail" resultType="cn.javabs.job.entity.User" parameterType="String">
          select * from  user
            <where>
                <if test="email != nul and email != '' ">
                   and  email =  #{email},
                </if>
            </where>
    </select>

    <!--按照条件(用户名或者性别或者学历)查询用户信息   返回的集合-->
    <select id="findUserByCondition" resultType="cn.javabs.job.entity.User" parameterType="String">
        select * from  user
        <where>
            <!--用户名 进行模糊查询-->
            <if test="username != nul and username != '' ">
                and username like concat('%',#{username},'%'),
            </if>
            <if test="sex != nul and sex != '' ">
                and sex =  #{sex},
            </if>
            <if test="degree != nul and degree != '' ">
                and degree = #{degree},
            </if>
        </where>
    </select>

    <!--根据用户编号查询用户信息-->
    <select id="findUserByUserId" resultType="cn.javabs.job.entity.User" parameterType="int">
        select * from  user
        <where>
            <if test="userId != nul and userId != '' ">
                and userId = #{userId}
            </if>
        </where>
    </select>

    <!--用户登录-->
    <select id="login" resultType="cn.javabs.job.entity.User" parameterType="cn.javabs.job.entity.User">
        select * from  user
        <where>
            <if test="username != nul and username != '' ">
                and username = #{username}
            </if>
            <if test="password != nul and password != '' ">
                and password = #{password}
            </if>
            <if test="type != nul and type != '' ">
                and type = #{type}
            </if>
        </where>
    </select>
</mapper>
6. 编写业务逻辑层接口
package cn.javabs.job.service;

import cn.javabs.job.entity.User;
import java.util.List;

public interface UserService {

    List<User> getAllUserList();

    User getUserByEmail(String email);

    User getUserByUserId(int userId);

    List<User> getUserByCondition(String condition);

    User userLogin(User user);

    int deleteUser(int userId);
    
    int editUser(User user);
    
    int addUser(User user);

}
7. 编写业务逻辑层接口的实现类
package cn.javabs.job.service.impl;

import cn.javabs.job.entity.User;
import cn.javabs.job.mapper.UserMapper;
import cn.javabs.job.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    @Qualifier("userMapper")
    private UserMapper userMapper;

    @Override
    public List<User> getAllUserList() {
        return userMapper.findAllUserList();
    }

    @Override
    public User getUserByEmail(String email) {
        return userMapper.findUserByEmail(email);
    }

    @Override
    public User getUserByUserId(int userId) {
        return userMapper.findUserByUserId(userId);
    }

    @Override
    public List<User> getUserByCondition(String condition) {
        return userMapper.findUserByCondition(condition);
    }

    @Override
    public User userLogin(User user) {
        return userMapper.login(user);
    }

    @Override
    public int deleteUser(int userId) {
        return userMapper.delUser(userId);
    }

    @Override
    public int editUser(User user) {
        return userMapper.editUser(user);
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }
}

8. 编写控制器类
package cn.javabs.job.controller;

import cn.javabs.job.entity.User;
import cn.javabs.job.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 后端用户管理的控制器
 */
@Controller
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    @Qualifier("userService")
    private UserService userService;

    @Value("${pagehelper.pageSize}")
    private int pageSize;


    @RequestMapping("userList")
    public ModelAndView userList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum){

        PageHelper.startPage(pageNum,pageSize);

        List<User> userList = userService.getAllUserList();

        PageInfo<User> pageInfo = new PageInfo<>(userList);

        ModelAndView mv = new ModelAndView();

        mv.addObject("userList",userList);
        mv.addObject("pageInfo",pageInfo);

        mv.setViewName("user");

        return  mv;
    }

}

9. 编写页面,模板引擎
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>

    <link rel="stylesheet" th:href="@{../static/component/style/components.css}" href="../static/component/style/components.css">
    <link rel="stylesheet" th:href="@{../static/css/bootstrap.css}" href="../static/css/bootstrap.css">
    <link rel="stylesheet" th:href="@{../static/css/plugins.css}" href="../static/css/plugins.css">
    <link rel="stylesheet" th:href="@{../static/css/main.css}" href="../static/css/main.css">
    <link rel="stylesheet" th:href="@{../static/css/themes.css}" href="../static/css/themes.css">
    <script th:src="@{../static/component/js/JQuery2.1.4.js}"></script>
    <script th:src="@{../static/component/js/bootstrap.min.js}"></script>
</head>

<body>
    <div id="body">
        <ol class="breadcrumb">
            <li class="active"><a href="#">系统</a></li>
            <li>用户列表</li>
        </ol>
        <div class="barboxs">

            <button class="btn btn-success pull-left " data-toggle="modal" data-target="#myModal" title="" data-placement="right" data-original-title="添加用户">
                <i class="fa fa-pencil-square-o"></i>
            </button>

            <button class="btn btn-danger pull-left ml10" data-toggle="tooltip" title="" data-placement="right" data-original-title="删除用户"><i class="fa fa-trash-o"></i></button>

            <div class="leftbox">
            
                <div class="liselect w300">
                    <div class="input-group">
                        <input type="text" id="example-input-typeahead" class="form-control example-typeahead" placeholder="请输入关键词">
                        <span class="input-group-btn">
                            <button class="btn btn-success"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        <div class="tablebox">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th class="text-center" width="50"><input type="checkbox" id="check5-all" name="check5-all"></th>
                        <th class="text-center">序号</th>
                        <th>用户账号</th>
                        <th>用户密码</th>
                
                        <th>电子邮件</th>
                        <th>手机号码</th>
                        <th>用户学历</th>
                        <th>用户性别</th>
                        <th>用户类别</th>
                        <th>创建时间</th>
                        <th class="text-center" width="85"><i class="fa fa-bolt"></i> 操作</th>
                    </tr>
                </thead>
                <tbody>

                    <tr th:each="user,userStatus:${userList}">
                        <td class="text-center"><input type="checkbox" id="check5-td1" name="check5-td1"></td>
                        <td class="cell-small text-center"><span th:text="${userStatus.index}">序号</span></td>
                        <td th:text="${user.username}">custom_admins</td>
                        <td th:text="${user.password}">custom_admins</td>
                        <td th:text="${user.email}">custom_admins</td>
                        <td th:text="${user.mobile}">custom_admins</td>
                        <td th:text="${user.degree}">custom_admins</td>

                        <span th:if="${user.sex} == 0">
                             <td >未知</td>
                        </span>

                        <span th:if="${user.sex} == 1">
                             <td >男</td>
                        </span>
                        <span th:if="${user.sex} == 2">
                             <td >女</td>
                        </span>

                        <td th:text="${user.type}">custom_admins</td>
        
                        <td>2021-3-22 11:04:49</td>
                        <td class="text-center">
                            <div class="btn-group">
                                <a href="javascript:void(0)" class="btn btn-xs btn-info"><i class="fa fa-globe"></i></a>
                                <a href="javascript:void(0)" class="btn btn-xs btn-success"><i class="fa fa-pencil"></i></a>
                                <a href="javascript:void(0)" class="btn btn-xs btn-danger"><i class="fa fa-trash-o"></i></a>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
</body>
</html>
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
前端开发 JavaScript
杨老师课堂之网页设计实训
杨老师课堂之网页设计实训
18 0
|
4月前
|
开发者
第十一期乘风伯乐活动开启,快来推荐你身边热爱分享的技术达人吧
乘风伯乐奖,面向阿里云开发者社区已入驻乘风者计划的博主(技术/星级/专家),邀请用户入驻乘风者计划即可获得乘风者定制周边等实物奖励。本期面向阿里云开发者社区寻找100位乘风伯乐,邀请人数月度TOP 1 获奖者(大于108人)可获得cherry樱桃MX3.0S键盘及伯乐之星证书!
1899 172
第十一期乘风伯乐活动开启,快来推荐你身边热爱分享的技术达人吧
|
测试技术 UED
【CSDN第五期竞赛】说说自己的感受吧
【CSDN第五期竞赛】说说自己的感受吧
83 0
|
运维 前端开发 小程序
自己学校里的实训做笔记
自己学校里的实训做笔记
自己学校里的实训做笔记
|
网络安全 Windows
千峰课程网安笔记(1)
1如何使两台虚拟机在同一局域网下互Ping以及关于单方面ping通的解决办法
108 0
千峰课程网安笔记(1)
|
安全 算法 区块链
北京大学肖臻老师《区块链技术与应用》公开课笔记11——课堂问答
北京大学肖臻老师《区块链技术与应用》公开课笔记11——课堂问答
359 0
|
弹性计算 物联网 大数据
大家好,我是阿里云高校君,一岁了
关键词:#一周岁 #高校君大数据 #豪横大礼 #训练营
384 0
|
人工智能 运维 开发者
【云栖精选】帮你把握“金三银四”,阿里开发者招聘节面经总结帖来袭
云栖精选,一文为你网罗本周云栖社区本周精华帖,精彩不容错过。换工作、找实习,那你一定不能错过“金三银四”,想要来阿里巴巴,一些笔试和面试技巧一定不能少。本期中,为大家选取了几篇关于阿里招聘节的相关内容。
7424 0
|
新零售 架构师 Java
云栖专辑| 阿里毕玄:程序员的成长路线
阿里基础设施负责人毕玄结合自己的经历跟大家讲述了他在各个角色上成长的感受,值得所有正为职业发展而迷茫的技术同学细细品味。
24827 0
|
DataWorks 大数据
【有奖征文】参与DataWorksV2.0征文活动,与专家面对面交流!
让我们共同普惠大数据,让人人都能玩转大数据!
1914 0