基于SSM框架的人事系统搭建(一)

系统的学习java已有半年左右时间,除去毕业设计还没有一项完整的作品,所以在闲暇之余打算写一个javaweb程序,巩固一下基础


(一)系统搭建这块,可以参考我之前的一篇文章,前端UI使用的H-ui.admin感谢H-ui.admin提供的技术支持!

(二)人事系统嘛,首先要有人员的管理,构建数据库如图

对应user类:

package com.zh.pojo;

public class User {
	private Integer id;
	private String username;
	private String password;
	private Integer age;
	private Integer sex;
	private String email;
	private Integer phone;
	private String address;
	private String createTime;
	private String position;
	private String department;
	private int education;
	private String state;

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public Integer getSex() {
		return sex;
	}
	public void setSex(Integer sex) {
		this.sex = sex;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Integer getPhone() {
		return phone;
	}
	public void setPhone(Integer phone) {
		this.phone = phone;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public String getPosition() {
		return position;
	}
	public void setPosition(String position) {
		this.position = position;
	}
	public String getDepartment() {
		return department;
	}
	public void setDepartment(String department) {
		this.department = department;
	}
	public int getEducation() {
		return education;
	}
	public void setEducation(int education) {
		this.education = education;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}

	
}

Controller类:

package com.zh.controller;


import java.util.List;
import java.util.Map;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.zh.pojo.User;
import com.zh.service.IUserService;


@Controller  
@RequestMapping("/user")  
public class UserController {
	@Resource  
    private IUserService userService;  
      

    /**
     * 查询用户信息
     * @return
     */
    @RequestMapping("/getUserList")  
    public String getUserList(HttpServletRequest request){  
    	List<Map<String,Object>> list=userService.getUserList();
    	request.setAttribute("list",list);  
        return "user/user-list";  
    }  
    /**
     * 查询用户合同信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/getUserContractList")  
    public List<User> getUserContractList(){  
    	List<User> list=userService.getUserContractList();
    	return list;  
    }  
    /**
     * 显示个人信息
     * @return
     */
    @RequestMapping("/user-show")  
    public String userShow(){  
        return "user/user-show";  
    }  
    /**
     * 查询合同信息
     * @return
     */
    @RequestMapping("/getUserContract")  
    public String getUserContract(){  
        return "user/userContract";  
    }
    /**
     * 显示用户信息概览
     * @return
     */
    @RequestMapping("/overview")  
    public String overview(){  
    	return "user/overview";  
    }
    /**
     * 统计部门
     * @return
     */
    @ResponseBody
    @RequestMapping("/getDep")  
    public List<User> getDep(){  
    	List<User> list=userService.getDep();
    	return list;  
    }
    /**
     * 统计性别
     * @return
     */
    @ResponseBody
    @RequestMapping("/getSex")  
    public List<User> getSex(){  
    	List<User> list=userService.getSex();
    	return list;  
    }   
    /**
     * 统计学历
     * @return
     */
    @ResponseBody
    @RequestMapping("/getEdu")  
    public List<User> getEdu(){  
    	List<User> list=userService.getEdu();
    	return list;  
    }
    /**
     * 查看用户详细信息
     * @return
     */
    @RequestMapping("/userShowWeb")  
    public String  userShowWeb(User user,HttpServletRequest request){  
    	List<User> list=userService.getUserShowWebById(user.getId());
    	request.setAttribute("list",list);  
    	return "user/user-show";
    }
}
Service接口:

package com.zh.service;


import java.util.List;
import java.util.Map;

import com.zh.pojo.User;

 
public interface IUserService {
//查询用户信息
List<Map<String,Object>> getUserList();
//查询合同信息
List<User> getUserContractList();
//统计部门
List<User> getDep();
//统计性别
List<User> getSex();
//统计学历
List<User> getEdu();
//根据ID查找用户信息
List<User> getUserShowWebById(Integer id);
}

ServiceImpl实现类:

package com.zh.service.impl;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.lang.reflect.Method;  
  

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zh.dao.IUserDao;
import com.zh.pojo.User;
import com.zh.service.IUserService;

@SuppressWarnings("unchecked")
@Service("userService")
public class UserServiceImpl implements IUserService {

	@Resource
    private IUserDao userDao;

	@Override
	public List<Map<String,Object>> getUserList() {
		List<Map<String,Object>> users=userDao.getUserList();
		List<Map<String,Object>> list=new ArrayList<Map<String, Object>>();
		for(int i=0;i<users.size();i++){
			Map<String, Object> maps = transBean2Map(users.get(i)); 
			list.add(maps);
		}
		return list;
	}
	
	// Bean --> Map 1: 利用Introspector和PropertyDescriptor 将Bean --> Map  
    public static Map<String, Object> transBean2Map(Object obj) {  
  
        if(obj == null){  
            return null;  
        }          
        Map<String, Object> map = new HashMap<String, Object>();  
        try {  
            BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());  
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();  
            for (PropertyDescriptor property : propertyDescriptors) {  
                String key = property.getName();  
  
                // 过滤class属性  
                if (!key.equals("class")) {  
                    // 得到property对应的getter方法  
                    Method getter = property.getReadMethod();  
                    Object value = getter.invoke(obj);  
  
                    map.put(key, value);  
                }  
  
            }  
        } catch (Exception e) {  
            System.out.println("transBean2Map Error " + e);  
        }  
  
        return map;  
  
    }

	@Override
	public List<User> getUserContractList() {
		return userDao.getUserContractList();
	}

	@Override
	public List<User> getDep() {
		return userDao.getDep();
	}

	@Override
	public List<User> getSex() {
		return userDao.getSex();
	}  
	
	@Override
	public List<User> getEdu() {
		return userDao.getEdu();
	}

	@Override
	public List<User> getUserShowWebById(Integer id) {
		return userDao.getUserShowWebById(id);
	}  
}

IDao接口:

package com.zh.dao;

import java.util.List;
import java.util.Map;

import com.zh.pojo.User;

public interface IUserDao {
	List<Map<String,Object>> getUserList() ;

	List<User> getUserContractList();

	List<User> getDep();

	List<User> getSex();

	List<User> getEdu();

	List<User> getUserShowWebById(Integer id);
}

mapper.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.zh.dao.IUserDao">
    <resultMap id="BaseResultMap" type="com.zh.pojo.User">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="username" property="username" jdbcType="VARCHAR"/>
        <result column="password" property="password" jdbcType="VARCHAR"/>
        <result column="age" property="age" jdbcType="INTEGER"/>
        <result column="sex" property="sex" jdbcType="INTEGER"/>
        <result column="email" property="email" jdbcType="VARCHAR"/>
        <result column="phone" property="phone" jdbcType="INTEGER"/>
        <result column="address" property="address" jdbcType="VARCHAR"/>
        <result column="createTime" property="createTime" jdbcType="VARCHAR"/>
        <result column="position" property="position" jdbcType="VARCHAR"/>
        <result column="department" property="department" jdbcType="VARCHAR"/>
        <result column="education" property="education" jdbcType="INTEGER"/>
        <result column="state" property="state" jdbcType="INTEGER"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, username, age,sex,address,createTime,position,department,education,state
    </sql>
    <select id="getUserList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
    </select>
     <select id="getUserContractList" resultType="hashmap">
        SELECT t_usercontract.`id`,t_user.`education`,t_user.`department`,t_usercontract.`cid`,t_user.`username`,t_user.`position`,t_usercontract.`type`,t_usercontract.`startDate`,t_usercontract.`endDate` FROM t_user LEFT JOIN  t_usercontract ON t_user.`id`=t_usercontract.`uid`
    </select>
    <select id="getDep" resultType="hashmap">
         SELECT department,COUNT(department) as num FROM t_user GROUP BY department
    </select>
    <select id="getSex" resultType="hashmap">
         SELECT sex ,COUNT(sex) AS num FROM t_user GROUP BY sex
    </select>
    <select id="getEdu" resultType="hashmap">
         SELECT education ,COUNT(education) AS num FROM t_user GROUP BY education
    </select>
    <select id="getUserShowWebById" parameterType="int" resultType="hashmap">
         SELECT username,remarks,sex,phone,email,address,createTime FROM t_user WHERE id=#{#id}
    </select>
    
</mapper>
多条件查询:

jsp:

  <div class="text-c"> 日期范围:
    <input type="text" οnfοcus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" name="datemin" class="input-text Wdate" style="width:120px;">
    -
    <input type="text" οnfοcus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" name="datemax" class="input-text Wdate" style="width:120px;">
    <input type="text" class="input-text" style="width:100px" placeholder="姓名" id="username" name="username">
    <input type="text" class="input-text" style="width:100px" placeholder="部门" id="department" name="department">
    <input type="text" class="input-text" style="width:100px" placeholder="职务" id="position" name="position">
    <input type="text" class="input-text" style="width:100px" placeholder="在职状态" id="state" name="state">
    <button type="submit" class="btn btn-success radius" id="" name="" ><i class="icon-search"></i> 搜用户</button>
    <button type="button" class="btn btn-primary  radius" id="reset" name="reset" ><i class="icon-search"></i> 重置</button>
  </div>
js:
	$("#reset").click(function() {
				$("#username").val("");
				$("#state").val("");
				$("#department").val("");
				$("#position").val("");
				$("#datemax").val("");
				$("#datemin").val("");
				$("#userListForm").submit();
	});
Controller:

    /**
     * 查询用户信息
     * @return
     * @throws UnsupportedEncodingException 
     */
    @RequestMapping(value="/getUserList")  
    public String selectUserList(String username,String department,String position,Integer state,String datemin,String datemax,HttpServletRequest request,Map<String, Object> map) throws UnsupportedEncodingException{  
		if(username!=null&&username!=""){
    	map.put("username", Encoding.encoding(username));}
		if(department!=""&&department!=null){
		map.put("department", Encoding.encoding(department));}
		if(position!=null&&position!=""){
		map.put("position", Encoding.encoding(position));}
		if(state!=null){
		map.put("state", state);}
		if(datemin!=""&&datemin!=null){
		map.put("datemin", Encoding.encoding(datemin));}
		if(datemax!=""&&datemax!=null){
		map.put("datemax", Encoding.encoding(datemax));}
    	List<Map<String,Object>> list=userService.getUserList(map);
    	int countOfUser=userService.countOfUser();//统计人数
    	request.setAttribute("countOfUser",countOfUser); 
    	request.setAttribute("list",list);  
    	return "user/user-list";    
    }  

mapper:
<select id="getUserList" resultMap="BaseResultMap" >
        select
        *
        from t_user where 1=1
              
	        <if test="username != null">    
	           and username = #{username}   
	        </if>    
	        <if test="department != null">    
	            and department = #{department}    
	        </if>    
	        <if test="position != null">    
	            and position = #{position}    
	        </if>    
	        <if test="state != null">    
	            and state = #{state}    
	        </if>    
	        <if test="datemin != null">    
	            and createTime >= #{datemin}
	        </if>    
	        <if test="datemax != null">    
	            and createTime <= #{datemax}
	        </if>     
   		 
    </select>
员工管理界面效果图:


目前仅完成:

劳动关系--入职、离职、转正

员工管理--概览、基本信息、合同信息

招聘管理--招聘需求、面试管理、人才库

系统管理--日志管理


其他功能进一步完善中……

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zgsdzczh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值