基于Spring MVC + Spring + MyBatis的【人事管理系统】

简介: 基于Spring MVC + Spring + MyBatis的【人事管理系统】

一、语言和环境


  1. 实现语言:JAVA语言
  2. 环境要求:IDEA/Eclipse + Tomcat + MySql
  3. 使用技术:Spring Boot 或 SSM

二、实现功能


随着公司业务的发展,需要一款在线人事管理系统,主要功能如下:

  1. 首页默认显示所有员工信息,如图1所示。

23.png



鼠标悬停某行数据时,以线性过渡动画显示光棒效果,如图2所示。


24.png


用户可以单独通过选择职位进行查询,也可以单独输入名字进行模糊查询,也可以两个条件一起查询,如图3所示。


25.png


点击添加人员,跳转到添加页面。输入数据后,点击确定添加,跳转主页面并刷新数据。


26.png


用户点击删除,弹出提示框,用户点击确定后,删除选中数据并显示最新数据,如图5所示


27.png


三、数据库设计


  1. 创建数据库(cqsw)。
  2. 创建数据表(tb_emp),结构如下。


28.png


创建数据表(tb_dept),结构如下。


29.png


四、实现步骤


SSM版本的实现步骤如下:


创建数据库和数据表,添加测试数据(至少添加4条测试数据)。

创建Web工程并创建各个包,导入工程所需的jar文件。

添加相关SSM框架支持。

配置项目所需要的各种配置文件(mybatis配置文件、spring配置文件、springMVC配置文件)。

创建实体类。

创建MyBatis操作数据库所需的Mapper接口及其Xml映射数据库操作语句文件。

创建业务逻辑相应的接口及其实现类,实现相应的业务,并在类中加入对DAO/Mapper的引用和注入。

创建Controller控制器类,在Controller中添加对业务逻辑类的引用和注入,并配置springMVC配置文件。

创建相关的操作页面,并使用CSS对页面进行美化。

实现页面的各项操作功能,并在相关地方进行验证,操作要人性化。

调试运行成功后导出相关的数据库文件并提交。


五、实现代码


1、MySQL数据库


cqsw.sql


30.png


/*
Navicat MySQL Data Transfer
Date: 2021-08-06 20:07:05
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `tb_dept`
-- ----------------------------
DROP TABLE IF EXISTS `tb_dept`;
CREATE TABLE `tb_dept` (
  `dept_id` int(11) NOT NULL AUTO_INCREMENT,
  `dept_name` varchar(50) NOT NULL,
  `dept_address` varchar(50) NOT NULL,
  PRIMARY KEY (`dept_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_dept
-- ----------------------------
INSERT INTO `tb_dept` VALUES ('1', '技术部', '重庆商务职业学院');
INSERT INTO `tb_dept` VALUES ('2', '销售部', '沙坪坝');
INSERT INTO `tb_dept` VALUES ('3', '市场部', '沙坪坝');
-- ----------------------------
-- Table structure for `tb_emp`
-- ----------------------------
DROP TABLE IF EXISTS `tb_emp`;
CREATE TABLE `tb_emp` (
  `emp_id` int(11) NOT NULL AUTO_INCREMENT,
  `emp_name` varchar(50) NOT NULL,
  `emp_position` varchar(50) NOT NULL,
  `emp_in_date` varchar(100) NOT NULL,
  `emp_salary` float NOT NULL,
  `dept_id` int(11) NOT NULL,
  PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7374 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_emp
-- ----------------------------
INSERT INTO `tb_emp` VALUES ('7369', '任盈盈', '职员', '1980-12-17', '800', '1');
INSERT INTO `tb_emp` VALUES ('7370', '杨逍', '销售人员', '1981-02-20', '1600', '2');
INSERT INTO `tb_emp` VALUES ('7371', '范瑶', '销售人员', '1981-02-22', '1250', '2');
INSERT INTO `tb_emp` VALUES ('7372', '任我行', '经理', '1981-04-02', '2975', '3');
INSERT INTO `tb_emp` VALUES ('7373', '卡卡西', '经理', '2021-08-06', '5000', '1');


2、项目Java代码

目录结构

cqsw_db


31.png


JAR包:


32.png


33.png


src

com.mhys.crm.controller【控制层】

Tb_empController.java


package com.mhys.crm.controller;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.mhys.crm.entity.TbEmp;
import com.mhys.crm.entity.Tb_emp_dept;
import com.mhys.crm.service.Tb_empService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import com.sun.swing.internal.plaf.metal.resources.metal;
@Controller
public class Tb_empController {
  @Resource
  private Tb_empService service;
  @RequestMapping("selectAll")
  public String selectAll(Model model,Tb_emp_dept tb_emp_dept) {
    if (tb_emp_dept.getEmpName()==null) {
      tb_emp_dept.setEmpName("");
    }
    if (tb_emp_dept.getEmpPosition()==null) {
      tb_emp_dept.setEmpPosition("");
    }
    List<Tb_emp_dept> list=service.selectAll(tb_emp_dept);
    model.addAttribute("empList", list);
    return "/account";
  }
  @RequestMapping("addPage")
  public String addPage() {
    return "/addAccount";
  }
  @RequestMapping("add")
  public String add(TbEmp tbEmp) {
    int rows=service.add(tbEmp);
    return "redirect:selectAll.do";
  }
  @RequestMapping("delete")
  public String  delete(int id) {
    int row=service.delete(id);
    return "redirect:selectAll.do";
  }
}


com.mhys.crm.dao【数据库访问层】

TbDeptMapper.java


package com.mhys.crm.dao;
import com.mhys.crm.entity.TbDept;
import java.util.List;
public interface TbDeptMapper {
    int deleteByPrimaryKey(Integer deptId);
    int insert(TbDept record);
    TbDept selectByPrimaryKey(Integer deptId);
    List<TbDept> selectAll();
    int updateByPrimaryKey(TbDept record);
}


TbEmpMapper.java


package com.mhys.crm.dao;
import com.mhys.crm.entity.TbEmp;
import com.mhys.crm.entity.Tb_emp_dept;
import java.util.List;
public interface TbEmpMapper {
    int deleteByPrimaryKey(Integer empId);
    int insert(TbEmp record);
    TbEmp selectByPrimaryKey(Integer empId);
    List<TbEmp> selectAll();
    int updateByPrimaryKey(TbEmp record);
    //多表连查
    List<Tb_emp_dept> selectEmp();
    //模糊查询
    List<Tb_emp_dept> selectEmpLike(Tb_emp_dept tb_emp_dept);
}


TbDeptMapper.xml


<?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="com.mhys.crm.dao.TbDeptMapper" >
  <resultMap id="BaseResultMap" type="com.mhys.crm.entity.TbDept" >
    <id column="dept_id" property="deptId" jdbcType="INTEGER" />
    <result column="dept_name" property="deptName" jdbcType="VARCHAR" />
    <result column="dept_address" property="deptAddress" jdbcType="VARCHAR" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tb_dept
    where dept_id = #{deptId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.mhys.crm.entity.TbDept" >
    insert into tb_dept (dept_id, dept_name, dept_address
      )
    values (#{deptId,jdbcType=INTEGER}, #{deptName,jdbcType=VARCHAR}, #{deptAddress,jdbcType=VARCHAR}
      )
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.mhys.crm.entity.TbDept" >
    update tb_dept
    set dept_name = #{deptName,jdbcType=VARCHAR},
      dept_address = #{deptAddress,jdbcType=VARCHAR}
    where dept_id = #{deptId,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select dept_id, dept_name, dept_address
    from tb_dept
    where dept_id = #{deptId,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap" >
    select dept_id, dept_name, dept_address
    from tb_dept
  </select>
</mapper>


TbEmpMapper.xml


<?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="com.mhys.crm.dao.TbEmpMapper" >
  <resultMap id="BaseResultMap" type="com.mhys.crm.entity.Tb_emp_dept" >
    <id column="emp_id" property="empId" jdbcType="INTEGER" />
    <result column="emp_name" property="empName" jdbcType="VARCHAR" />
    <result column="emp_position" property="empPosition" jdbcType="VARCHAR" />
    <result column="emp_in_date" property="empInDate" jdbcType="DATE" />
    <result column="emp_salary" property="empSalary" jdbcType="REAL" />
    <result column="dept_id" property="deptId" jdbcType="INTEGER" />
    <result column="dept_name" property="deptName" jdbcType="VARCHAR" />
    <result column="dept_address" property="deptAddress" jdbcType="VARCHAR" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tb_emp
    where emp_id = #{empId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.mhys.crm.entity.TbEmp" >
    insert into tb_emp (emp_id, emp_name, emp_position, 
      emp_in_date, emp_salary, dept_id
      )
    values (#{empId,jdbcType=INTEGER}, #{empName,jdbcType=VARCHAR}, #{empPosition,jdbcType=VARCHAR}, 
      #{empInDate,jdbcType=DATE}, #{empSalary,jdbcType=REAL}, #{deptId,jdbcType=INTEGER}
      )
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.mhys.crm.entity.TbEmp" >
    update tb_emp
    set emp_name = #{empName,jdbcType=VARCHAR},
      emp_position = #{empPosition,jdbcType=VARCHAR},
      emp_in_date = #{empInDate,jdbcType=DATE},
      emp_salary = #{empSalary,jdbcType=REAL},
      dept_id = #{deptId,jdbcType=INTEGER}
    where emp_id = #{empId,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select emp_id, emp_name, emp_position, emp_in_date, emp_salary, dept_id
    from tb_emp
    where emp_id = #{empId,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap" >
    select emp_id, emp_name, emp_position, emp_in_date, emp_salary, dept_id
    from tb_emp
  </select>
  <select id="selectEmp" resultMap="BaseResultMap" >
    SELECT emp_id, emp_name, emp_position, emp_in_date, emp_salary,dept_name,
     dept_address FROM tb_emp e,tb_dept d WHERE e.dept_id=d.dept_id 
  </select>
  <select id="selectEmpLike" resultMap="BaseResultMap" >
    SELECT emp_id, emp_name, emp_position, emp_in_date, emp_salary,dept_name,
     dept_address FROM tb_emp e LEFT JOIN tb_dept d on e.dept_id=d.dept_id WHERE emp_position LIKE "%"#{empPosition}"%" 
     and emp_name like "%"#{empName}"%"
  </select>
</mapper>


com.mhys.crm.entity【实体的包】

Tb_emp_dept.java


package com.mhys.crm.entity;
import java.util.Date;
public class Tb_emp_dept {
  private Integer empId;
    private String empName;
    private String empPosition;
    private Date empInDate;
    private Float empSalary;
    private Integer deptId;
    private String deptName;
    private String deptAddress;
  public Integer getEmpId() {
    return empId;
  }
  public void setEmpId(Integer empId) {
    this.empId = empId;
  }
  public String getEmpName() {
    return empName;
  }
  public void setEmpName(String empName) {
    this.empName = empName;
  }
  public String getEmpPosition() {
    return empPosition;
  }
  public void setEmpPosition(String empPosition) {
    this.empPosition = empPosition;
  }
  public Date getEmpInDate() {
    return empInDate;
  }
  public void setEmpInDate(Date empInDate) {
    this.empInDate = empInDate;
  }
  public Float getEmpSalary() {
    return empSalary;
  }
  public void setEmpSalary(Float empSalary) {
    this.empSalary = empSalary;
  }
  public Integer getDeptId() {
    return deptId;
  }
  public void setDeptId(Integer deptId) {
    this.deptId = deptId;
  }
  public String getDeptName() {
    return deptName;
  }
  public void setDeptName(String deptName) {
    this.deptName = deptName;
  }
  public String getDeptAddress() {
    return deptAddress;
  }
  public void setDeptAddress(String deptAddress) {
    this.deptAddress = deptAddress;
  }
  public Tb_emp_dept(Integer empId, String empName, String empPosition, Date empInDate, Float empSalary,
      Integer deptId, String deptName, String deptAddress) {
    super();
    this.empId = empId;
    this.empName = empName;
    this.empPosition = empPosition;
    this.empInDate = empInDate;
    this.empSalary = empSalary;
    this.deptId = deptId;
    this.deptName = deptName;
    this.deptAddress = deptAddress;
  }
  public Tb_emp_dept() {
    super();
  }
  @Override
  public String toString() {
    return "Tb_emp_dept [empId=" + empId + ", empName=" + empName + ", empPosition=" + empPosition + ", empInDate="
        + empInDate + ", empSalary=" + empSalary + ", deptId=" + deptId + ", deptName=" + deptName
        + ", deptAddress=" + deptAddress + "]";
  }
}


TbDept.java


package com.mhys.crm.entity;
public class TbDept {
    private Integer deptId;
    private String deptName;
    private String deptAddress;
    public Integer getDeptId() {
        return deptId;
    }
    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }
    public String getDeptName() {
        return deptName;
    }
    public void setDeptName(String deptName) {
        this.deptName = deptName == null ? null : deptName.trim();
    }
    public String getDeptAddress() {
        return deptAddress;
    }
    public void setDeptAddress(String deptAddress) {
        this.deptAddress = deptAddress == null ? null : deptAddress.trim();
    }
}


TbEmp.java


package com.mhys.crm.entity;
import java.util.Date;
public class TbEmp {
    private Integer empId;
    private String empName;
    private String empPosition;
    private String empInDate;
    private Float empSalary;
    private Integer deptId;
    public Integer getEmpId() {
        return empId;
    }
    public void setEmpId(Integer empId) {
        this.empId = empId;
    }
    public String getEmpName() {
        return empName;
    }
    public void setEmpName(String empName) {
        this.empName = empName == null ? null : empName.trim();
    }
    public String getEmpPosition() {
        return empPosition;
    }
    public void setEmpPosition(String empPosition) {
        this.empPosition = empPosition == null ? null : empPosition.trim();
    }
    public String getEmpInDate() {
        return empInDate;
    }
    public void setEmpInDate(String empInDate) {
        this.empInDate = empInDate;
    }
    public Float getEmpSalary() {
        return empSalary;
    }
    public void setEmpSalary(Float empSalary) {
        this.empSalary = empSalary;
    }
    public Integer getDeptId() {
        return deptId;
    }
    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }
}


com.mhys.crm.service【业务处理类】

Tb_empService.java


package com.mhys.crm.service;
import java.util.List;
import com.mhys.crm.entity.TbEmp;
import com.mhys.crm.entity.Tb_emp_dept;
public interface Tb_empService {
  //查询
  List<Tb_emp_dept> selectAll(Tb_emp_dept tb_emp_dept);
  //添加
  int add(TbEmp tbEmp);
  int delete(int id);
}


com.mhys.crm.service.impl【业务处理的实现类】

Tb_empServiceImpl.java


package com.mhys.crm.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.mhys.crm.dao.TbEmpMapper;
import com.mhys.crm.entity.TbEmp;
import com.mhys.crm.entity.Tb_emp_dept;
import com.mhys.crm.service.Tb_empService;
@Service
public class Tb_empServiceImpl implements Tb_empService {
  @Resource
  private TbEmpMapper mapper;
  @Override
  public List<Tb_emp_dept> selectAll(Tb_emp_dept tb_emp_dept) {
    // TODO Auto-generated method stub
    System.out.println(tb_emp_dept.getEmpName());
    System.out.println(tb_emp_dept.getEmpPosition());
    if (tb_emp_dept.getEmpName().equals("")&&tb_emp_dept.getEmpPosition().equals("")) {
      List<Tb_emp_dept> list=mapper.selectEmp();
      return list;
    }else {
      List<Tb_emp_dept> list=mapper.selectEmpLike(tb_emp_dept);
      return list;
    }
  }
  @Override
  public int add(TbEmp tbEmp) {
    // TODO Auto-generated method stub
    int rows=mapper.insert(tbEmp);
    return rows;
  }
  @Override
  public int delete(int id) {
    // TODO Auto-generated method stub
    return mapper.deleteByPrimaryKey(id);
  }
}


genter【实体类自动生成包】

Tb_empController.java


package genter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
public class Generator {
/*
 * targetRuntime="MyBatis3Simple", 不生成Example
 */
public void generateMyBatis() {
  //MBG执行过程中的警告信息
  List<String> warnings = new ArrayList<String>();
  //当生成的代码重复时,覆盖原代码
  boolean overwrite = true ;
  String generatorFile = "/generatorConfig.xml";
  //String generatorFile = "/generator/generatorConfigExample.xml";
  //读取MBG配置文件
  InputStream is = Generator.class.getResourceAsStream(generatorFile);
  ConfigurationParser cp = new ConfigurationParser(warnings);
  Configuration config;
  try {
    config = cp.parseConfiguration(is);
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
  } catch (IOException e) {
    e.printStackTrace();
  } catch (XMLParserException e) {
    e.printStackTrace();
  } catch (InvalidConfigurationException e) {
    e.printStackTrace();
  } catch (SQLException e) {
    e.printStackTrace();
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  for (String warning : warnings) {
    System.out.println(warning);
  }
}
public static void main(String[] args) {
  Generator generator = new Generator();
  generator.generateMyBatis();
}
}


generatorConfig.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- 配置生成器 -->
<generatorConfiguration>
  <context id="MySQLContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
    <!-- 配置前置分隔符和后置分隔符 -->
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>
    <!-- 配置注释信息 -->
    <commentGenerator>
      <!-- 不生成注释 -->
      <property name="suppressAllComments" value="true"/>
      <property name="suppressDate" value="true"/>
      <property name="addRemarkComments" value="true"/>
    </commentGenerator>
    <!-- 数据库连接配置 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" 
        connectionURL="jdbc:mysql://localhost:3306/cqsw"
        userId="root" password="123456">
    </jdbcConnection>
    <!-- targetPackage:生成实体类存放的包名, targetProject:指定目标项目路径,可以使用相对路径或绝对路径 -->
    <javaModelGenerator targetPackage="com.mhys.crm.entity" targetProject="src">
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- 配置SQL映射器Mapper.xml文件的属性 -->
    <sqlMapGenerator targetPackage="com.mhys.crm.dao" targetProject="src"/>
    <!-- type="XMLMAPPER":所有的方法都在XML中,接口调用依赖XML文件 -->
    <javaClientGenerator targetPackage="com.mhys.crm.dao" type="XMLMAPPER" 
                targetProject="src"/>
    <!-- 生成所有表的映射 -->
    <table tableName="%"></table>   
  </context>
</generatorConfiguration>


resource

mybatis

SqlMapConfig.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <typeAliases>
    <package name="com.mhys.crm.entity"/>
  </typeAliases>
</configuration>


spring

applicationContext-dao.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
  <context:property-placeholder location="classpath:database.properties" />
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="driverClassName" value="${db.driverClass}" />
    <property name="url" value="${db.jdbcUrl}" />
    <property name="username" value="${db.user}" />
    <property name="password" value="${db.password}" />
  </bean>
  <bean class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
    <property name="dataSource" ref="dataSource" />
  </bean>
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.mhys.crm.dao" />
  </bean>
</beans>


applicationContext-service.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
  <context:component-scan base-package="com.mhys.crm.service" />
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
  </bean>
  <tx:annotation-driven transaction-manager="transactionManager" />
</beans>


spring-mvc.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  <context:component-scan base-package="com.mhys.crm.controller" />
  <mvc:annotation-driven />
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp" />
    <property name="suffix" value=".jsp" />
  </bean>
</beans>


WebContent

jsp

index.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
  <script>
    window.location.href = "selectAll.do";
  </script>
</body>
</html>


account.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>人事管理系统</title>
<style>
      *{
        margin: 0;padding: 0;
      }
      table,td,th{
        border-collapse: collapse;
        border-spacing: 0;
      }
      table{
        text-align:center;
        width: 90%;
        margin: 0 auto;
      }
      td,th{
        padding: 5px 10px;
        border: 1px solid black;
      }
      th{
        background: #a1a4b5;
        font-size: 1.3rem;
        font-weight: 450;
        color: white; 
        cursor: pointer;
      }
      .form{
        width:90%;
        padding:10px;
        margin: 0 auto;
      }
      .bottom{
        width:90%;
        padding:10px;
        margin: 0 auto;
      }
      h1{
        text-align:center;
      }
      tr:hover{
        box-shadow: #8f8fff 10px 10px 30px 5px ;
        background: #a1a4b5;
      }
      .form-group{
        padding: 20px;
      }
    </style>
</head>
<body>
  <div class="form">
  <h1>人事管理系统</h1><br/>
    <fieldset>
        <legend>
          搜索
        </legend>
        <div class="form-group">
          <form action="selectAll.do">
            <label>职位:</label>
            <select name="empPosition">
              <option value="">请选择---</option>
              <option>总裁</option>
              <option>经理</option>
              <option>销售人员</option>
              <option>职员</option>
            </select>
            <label>姓名:</label>
            <input type="text" name="empName" />
            <input type="submit" value="查看结果">
          </form>
        </div>
      </fieldset>
  </div>
  <table>
    <tr>
      <th>员工编号</th>
      <th>姓名</th>
      <th>职位</th>
      <th>入职日期</th>
      <th>薪资</th>
      <th>部门名称</th>
      <th>部门地址</th>
      <th>操作</th>
    </tr>
      <c:forEach items="${empList }" var="emp">
        <tr>
          <td>${emp.empId }</td>
          <td>${emp.empName }</td>
          <td>${emp.empPosition }</td>
          <td><fmt:formatDate value="${emp.empInDate }" pattern="yyyy-MM-dd"/></td>
          <td>${emp.empSalary }</td>
          <td>${emp.deptName }</td>
          <td>${emp.deptAddress }</td>
          <td>
            <button style="padding: 4px 10px" onclick="del(${emp.empId })" >删除</button>
              <%-- <a style="color: red" onclick="del(${emp.empId })" >删除</a> --%>
          </td>
        </tr>
      </c:forEach>
  </table>
  <div class="bottom">
    <a href="addPage.do">添加员工</a>
    共${empList.size() }条数据
  </div>
  <script type="text/javascript">
  function del(id){
      if(confirm("确认要删除吗?")){
          return window.location.href="delete.do?id="+id;
      }else {
          return false;
      }
   };
  </script>
</body>
</html>


addAccount.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
  <h1>添加账户</h1>
  <form action="add.do">
    <input type="hidden" name="id" />
    <p>
      <label>姓名:</label>
      <input type="text" name="empName"  />
    </p>
    <p>
      <label>职位:</label>
              <select name="empPosition">
                <option></option>
                <option>总裁</option>
                <option>经理</option>
                <option>销售人员</option>
                <option>职员</option>
              </select>
    </p>
    <p>
      <label>入职日期:</label>
      <input type="date" name="empInDate"/>
    </p>
    <p>
      <label>薪资:</label>
      <input type="number" name="empSalary"/>
    </p>
    <p>
      <label>部门:</label>
      <select name="deptId">
        <option></option>
        <option value="1">技术部</option>
        <option value="2">销售部</option>
        <option value="3">市场部</option>
      </select>
    </p>
    <p>
      <button type="submit">提交</button>
      <input type="button" onclick="window.history.back();" value="取消">
    </p>
  </form>
</body>
</html>



相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
前端开发 Java 微服务
《深入理解Spring》:Spring、Spring MVC与Spring Boot的深度解析
Spring Framework是Java生态的基石,提供IoC、AOP等核心功能;Spring MVC基于其构建,实现Web层MVC架构;Spring Boot则通过自动配置和内嵌服务器,极大简化了开发与部署。三者层层演进,Spring Boot并非替代,而是对前者的高效封装与增强,适用于微服务与快速开发,而深入理解Spring Framework有助于更好驾驭整体技术栈。
|
存储 人工智能 自然语言处理
用Spring AI搭建本地RAG系统:让AI成为你的私人文档助手
想让AI帮你读懂PDF文档吗?本文教你用Spring AI和Ollama搭建一个本地RAG系统,让AI成为你的私人文档助手。无需GPU,无需云端API,只需几行代码,你的文档就能开口说话了!
2378 2
|
Java 数据库连接 API
Java 对象模型现代化实践 基于 Spring Boot 与 MyBatis Plus 的实现方案深度解析
本文介绍了基于Spring Boot与MyBatis-Plus的Java对象模型现代化实践方案。采用Spring Boot 3.1.2作为基础框架,结合MyBatis-Plus 3.5.3.1进行数据访问层实现,使用Lombok简化PO对象,MapStruct处理对象转换。文章详细讲解了数据库设计、PO对象实现、DAO层构建、业务逻辑封装以及DTO/VO转换等核心环节,提供了一个完整的现代化Java对象模型实现案例。通过分层设计和对象转换,实现了业务逻辑与数据访问的解耦,提高了代码的可维护性和扩展性。
694 1
|
前端开发 Java API
Spring Cloud Gateway Server Web MVC报错“Unsupported transfer encoding: chunked”解决
本文解析了Spring Cloud Gateway中出现“Unsupported transfer encoding: chunked”错误的原因,指出该问题源于Feign依赖的HTTP客户端与服务端的`chunked`传输编码不兼容,并提供了具体的解决方案。通过规范Feign客户端接口的返回类型,可有效避免该异常,提升系统兼容性与稳定性。
1102 0
|
SQL Java 数据库连接
Spring、SpringMVC 与 MyBatis 核心知识点解析
我梳理的这些内容,涵盖了 Spring、SpringMVC 和 MyBatis 的核心知识点。 在 Spring 中,我了解到 IOC 是控制反转,把对象控制权交容器;DI 是依赖注入,有三种实现方式。Bean 有五种作用域,单例 bean 的线程安全问题及自动装配方式也清晰了。事务基于数据库和 AOP,有失效场景和七种传播行为。AOP 是面向切面编程,动态代理有 JDK 和 CGLIB 两种。 SpringMVC 的 11 步执行流程我烂熟于心,还有那些常用注解的用法。 MyBatis 里,#{} 和 ${} 的区别很关键,获取主键、处理字段与属性名不匹配的方法也掌握了。多表查询、动态
565 0
|
JSON 前端开发 Java
第05课:Spring Boot中的MVC支持
第05课:Spring Boot中的MVC支持
579 0
|
设计模式 前端开发 JavaScript
Spring MVC(一)【什么是Spring MVC】
Spring MVC(一)【什么是Spring MVC】
|
前端开发 Java 关系型数据库
基于ssm框架旅游网旅游社交平台前后台管理系统(spring+springmvc+mybatis+maven+tomcat+html)
基于ssm框架旅游网旅游社交平台前后台管理系统(spring+springmvc+mybatis+maven+tomcat+html)
420 0
|
前端开发 Java Go
Spring MVC 和 Spring Boot 的区别
Spring MVC 和 Spring Boot 的区别
813 0
|
Java Spring
springmvc中spring提供的中文乱码解决问题
可以解决浏览器的乱码问题
332 0

热门文章

最新文章