基于javaweb+jsp的人事员工管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、部门模块、员工模块、请假模块、工资模块的增删改查管理
g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));
}
HttpSession session = request.getSession();
session.setMaxInactiveInterval(5 * 60);
// 将验证码保存在session对象中,key为validation_code
session.setAttribute("validationCode", validationCode.toString());
g.dispose();// 关闭Graphics对象
OutputStream os = response.getOutputStream();
ImageIO.write(image, "JPEG", os);// 以JPEG格式向客户端发送图形验证码
}
@RequestMapping("authResetPassword")
public void resetPassword(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
<div class="form-group">
<label class="col-sm-3 control-label">性别:</label>
<div class="col-sm-5">
<input name="userSex" type="radio" value="男" ${vo.userSex=='男'?'checked':''}/> 男
<input name="userSex" type="radio" value="女" ${vo.userSex=='女'?'checked':''}/> 女
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">手机:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="userPhone" name="userPhone" value="${vo.userPhone}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">备注:</label>
<div class="col-sm-5">
<textarea rows="3" class="form-control" id="userText" name="userText" placeholder="请输入内容......">${vo.userText}</textarea>
</div>
</div>
<div class="form-group">
<li class="active"><a href="#">编辑</a></li>
</ul>
<br/>
<form class="form-horizontal" role="form" action="userEdit" method="post" onsubmit="return check()">
<input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
<div class="form-group">
<label class="col-sm-3 control-label">用户名:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="username" name="username" value="${vo.username}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">密码:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="password" name="password" value="${vo.password}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">姓名:</label>
<!--列表-->
<select id="findAllSplit" parameterType="java.util.Map" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM `t_salary`
<where>
<if test="searchColumn != null and searchColumn != '' and keyword != null and keyword != ''">
${searchColumn} LIKE CONCAT('%',#{keyword},'%') AND
</if>
1=1
</where>
ORDER BY id ASC
<if test="startIndex != null and pageSize != null">
LIMIT #{startIndex},#{pageSize};
</if>
</select>
<!--数量-->
<select id="getAllCount" parameterType="java.util.Map" resultType="Integer">
SELECT COUNT(*) FROM `t_salary`
<where>
<if test="searchColumn != null and searchColumn != '' and keyword != null and keyword != ''">
${searchColumn} LIKE CONCAT('%',#{keyword},'%') AND
</if>
1=1
</where>
<input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
<div class="form-group">
<label class="col-sm-3 control-label">工号:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="leaveNo" name="leaveNo" value="${vo.leaveNo}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">姓名:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="leaveName" name="leaveName" value="${vo.leaveName}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">开始:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="leaveStart" name="leaveStart" value="${vo.leaveStart}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">结束:</label>
<div class="col-sm-5">
<input type="button" class="btn btn-line btn-primary btn-sm" value="返回" onclick="javascript:history.back(-1);">
</div>
</div>
</form>
</div>
</body>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
if (document.getElementById("employeeName").value.trim().length == 0) {
alert("姓名不能为空!");
return false;
}
if (document.getElementById("employeePhone").value.trim().length == 0) {
alert("联系方式不能为空!");
return false;
}
if (document.getElementById("employeeDept").value.trim().length == 0) {
alert("所属部门不能为空!");
return false;
}
<if test ='salaryMoney != null'>`salary_money` = #{salaryMoney},</if>
<if test ='salaryText != null'>`salary_text` = #{salaryText}</if>
</set>
WHERE `id` = #{id}
</update>
<!--获取-->
<select id="findById" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM `t_salary` WHERE `id` = #{id}
</select>
<!--列表-->
<select id="findAllSplit" parameterType="java.util.Map" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM `t_salary`
<where>
<if test="searchColumn != null and searchColumn != '' and keyword != null and keyword != ''">
${searchColumn} LIKE CONCAT('%',#{keyword},'%') AND
</if>
1=1
</where>
*/
@RequestMapping("employeeAdd")
public void add(HttpServletResponse response, HttpServletRequest request) throws IOException {
Employee vo = new Employee();
//取出页面传进来的参数
vo.setEmployeeName(Util.decode(request, "employeeName"));
vo.setEmployeeSex(Util.decode(request, "employeeSex"));
vo.setEmployeePhone(Util.decode(request, "employeePhone"));
vo.setEmployeeDept(Util.decode(request, "employeeDept"));
vo.setEmployeeJob(Util.decode(request, "employeeJob"));
vo.setEmployeeNo(Util.decode(request, "employeeNo"));
vo.setEmployeeAge(Util.decode(request, "employeeAge"));
vo.setEmployeeEducation(Util.decode(request, "employeeEducation"));
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping
</resultMap>
<sql id="Base_Column_List">
`id`,`leave_no`,`leave_name`,`leave_start`,`leave_end`,`leave_days`,`leave_reason`,`leave_text`
</sql>
<!--新增-->
<insert id="doCreate" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.demo.vo.Leave">
INSERT INTO `t_leave`
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test ='id != null'>`id`,</if>
<if test ='leaveNo != null'>`leave_no`,</if>
<if test ='leaveName != null'>`leave_name`,</if>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test ='id != null'>#{id},</if>
<if test ='leaveNo != null'>#{leaveNo},</if>
<if test ='leaveName != null'>#{leaveName},</if>
<if test ='leaveStart != null'>#{leaveStart},</if>
<if test ='leaveEnd != null'>#{leaveEnd},</if>
<if test ='leaveDays != null'>#{leaveDays},</if>
<if test ='leaveReason != null'>#{leaveReason},</if>
<if test ='leaveText != null'>#{leaveText}</if>
</trim>
</insert>
<!--批量删除-->
<delete id="doRemoveBatch" parameterType="java.util.Collection">
DELETE FROM `t_leave` WHERE `id` IN
<foreach collection="list" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<!--修改-->
<update id="doUpdate" parameterType="com.demo.vo.Leave">
UPDATE `t_leave`
<set>
<if test ='id != null'>`id` = #{id},</if>
System.out.println("username=" + username);
System.out.println("password=" + password);
Map<String, Object> params = new HashMap();
params.put("searchColumn", "username");//使用`username`字段进行模糊查询
params.put("keyword", username);
params.put("startIndex", 0);
params.put("pageSize", Long.MAX_VALUE);
List<User> list = (List<User>) userService.list(params).get("list");
for (User user : list) {
if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
request.getRequestDispatcher("register.jsp").forward(request, response);
return;
}
}
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeAdd")
public void add(HttpServletResponse response, HttpServletRequest request) throws IOException {
Employee vo = new Employee();
//取出页面传进来的参数
vo.setEmployeeName(Util.decode(request, "employeeName"));
vo.setEmployeeSex(Util.decode(request, "employeeSex"));
vo.setEmployeePhone(Util.decode(request, "employeePhone"));
vo.setEmployeeDept(Util.decode(request, "employeeDept"));
vo.setEmployeeJob(Util.decode(request, "employeeJob"));
vo.setEmployeeNo(Util.decode(request, "employeeNo"));
vo.setEmployeeAge(Util.decode(request, "employeeAge"));
vo.setEmployeeEducation(Util.decode(request, "employeeEducation"));
vo.setEmployeeIntime(Util.decode(request, "employeeIntime"));
vo.setEmployeeText(Util.decode(request, "employeeText"));
//调用Service层的增加(insert)方法
employeeService.insert(vo);
this.redirectList(request, response);
<input type="text" class="form-control" id="username" name="username" value="${vo.username}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">密码:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="password" name="password" value="${vo.password}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">姓名:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="realName" name="realName" value="${vo.realName}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">性别:</label>
<div class="col-sm-5">
<input name="userSex" type="radio" value="男" ${vo.userSex=='男'?'checked':''}/> 男
<input name="userSex" type="radio" value="女" ${vo.userSex=='女'?'checked':''}/> 女
</div>
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping
public class LeaveController {
@Autowired
private LeaveService leaveService;
/**
* 增加请假
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("leaveAdd")
public void add(HttpServletResponse response, HttpServletRequest request) throws IOException {
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"deptGet", "deptEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = Util.decode(request, "id");//取出主键id
Dept vo = deptService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("dept_" + to + ".jsp");
}
/**
* 根据条件查询部门的列表并跳转回页面
*
* @param response