请帮检查测试一下代码,登陆界面无法登录console报错,form表单提交也有问题,不能同步到数据库
ftl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>请假申请</title>
<link rel="stylesheet" href="/resources/layui/css/layui.css">
<style>
/*表单容器*/
.ns-container {
position: absolute;
width: 500px;
height: 450px;
top: 150px;
left: 50%;
margin-left: -250px;
padding: 20px;
box-sizing: border-box;
border: 1px solid #cccccc;
}
</style>
</head>
<body>
<div class="layui-row">
<blockquote class="layui-elem-quote">
<h2>请假申请</h2>
</blockquote>
<table id="grdNoticeList" lay-filter="grdNoticeList"></table>
</div>
<div class="ns-container">
<h1 style="text-align: center;margin-bottom: 20px">请假申请单</h1>
<form class="layui-form">
<!--基本信息-->
<div class="layui-form-item">
<label class="layui-form-label">部门</label>
<div class="layui-input-block">
<div class="layui-col-md12" style="padding-top: 10px;">
${current_department.departmentName}
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">申请人</label>
<div class="layui-input-block">
<div class="layui-col-md12" style="padding-top: 10px;">
${current_employee.name}[${current_employee.title}]
</div>
</div>
</div>
<!--请假类型下拉框-->
<div class="layui-form-item">
<label class="layui-form-label">请假类别</label>
<div class="layui-input-block layui-col-space5">
<select name="formType" lay-verify="required" lay-filter="cityCode">
<option value="1">事假</option>
<option value="2">病假</option>
<option value="3">工伤假</option>
<option value="4">婚嫁</option>
<option value="5">产假</option>
<option value="6">丧假</option>
</select>
</div>
</div>
<!--请假时长日期选择框-->
<div class="layui-form-item">
<label class="layui-form-label">请假时长</label>
<div class="layui-input-block layui-col-space5">
<input name="leaveRange" type="text" class="layui-input" id="daterange" placeholder=" - ">
<input id="startTime" name="startTime" type="hidden">
<input id="endTime" name="endTime" type="hidden">
</div>
</div>
<!--请假事由-->
<div class="layui-form-item">
<label class="layui-form-label">请假事由</label>
<div class="layui-input-block layui-col-space5">
<input name="reason" type="text" lay-verify="required|mobile" placeholder="" autocomplete="off" class="layui-input">
</div>
</div>
<!--提交按钮-->
<div class="layui-form-item " style="text-align: center">
<button class="layui-btn" type="button" lay-submit lay-filter="sub">立即申请</button>
</div>
</form>
</div>
<script src="/resources/layui/layui.all.js"></script>
<script src="/resources/sweetalert2.all.min.js"></script>
<script>
var layDate = layui.laydate; //Layui日期选择框JS对象
var layForm = layui.form; //layui表单对象
var $ = layui.$; //jQuery对象
//日期时间范围
layDate.render({
elem: '#daterange'
,type: 'datetime'
,range: true
,format: 'yyyy年M月d日H时'
,done: function(value, start, end){
//选择日期后出发的时间,设置startTime与endTime隐藏域
var startTime = start.year + "-" + start.month + "-" + start.date + "-" + start.hours;
var endTime = end.year + "-" + end.month + "-" + end.date + "-" + end.hours;
console.info("请假开始时间",startTime);
$("#startTime").val(startTime);
console.info("请假结束时间",endTime);
$("#endTime").val(endTime);
}
});
//表单提交时间
layForm.on('submit(sub)', function(data){
console.info("向服务器提交的表单数据",data.field);
$.post("/leave/create",data.field,function (json) {
console.info(json);
if(json.code == "0"){
/*SweetAlert2确定对话框*/
swal({
type: 'success',
html: "<h2>请假单已提交,等待上级审批</h2>",
confirmButtonText: "确定"
}).then(function (result) {
window.location.href="/forward/notice";
});
}else{
swal({
type: 'warning',
html: "<h2>" + json.message + "</h2>",
confirmButtonText: "确定"
});
}
},"json");
return false;
});
</script>
</body>
</html>
index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>慕课网办公OA系统</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<!-- Layui后台布局CSS -->
<div class="layui-layout layui-layout-admin">
<!--头部导航栏-->
<div class="layui-header">
<!--系统标题-->
<div class="layui-logo" style="font-size:18px">慕课网办公OA系统</div>
<!--右侧当前用户信息-->
<ul class="layui-nav layui-layout-right">
<li class="layui-nav-item">
<a href="javascript:void(0)">
<!--图标-->
<span class="layui-icon layui-icon-user" style="font-size: 20px">
</span>
<!--用户信息-->
${current_employee.name}[${current_department.departmentName}-${current_employee.title}]
</a>
</li>
<!--注销按钮-->
<li class="layui-nav-item"><a href="/logout">注销</a></li>
</ul>
</div>
<!--左侧菜单栏-->
<div class="layui-side layui-bg-black">
<!--可滚动菜单-->
<div class="layui-side-scroll">
<!--可折叠导航栏-->
<ul class="layui-nav layui-nav-tree">
<#list node_list as node>
<!--父节点-->
<#if node.nodeType == 1>
<li class="layui-nav-item layui-nav-itemed">
<a href="javascript:void(0)">${node.nodeName}</a>
<dl class="layui-nav-child module" data-node-id="${node.nodeId}"></dl>
</li>
</#if>
<!--子节点-->
<#if node.nodeType == 2>
<dd class="function" data-parent-id="${node.parentId}">
<a href="${node.url}" target="ifmMain">${node.nodeName}</a>
</dd>
</#if>
</#list>
</ul>
</div>
</div>
<!--主体部分采用iframe嵌入其他页面-->
<div class="layui-body" style="overflow-y: hidden">
<iframe name="ifmMain" style="border: 0px;width: 100%;height: 100%"></iframe>
</div>
<!--版权信息-->
<div class="layui-footer">
Copyright © imooc. All Rights Reserved.
</div>
</div>
<!--LayUI JS文件-->
<script src="/resources/layui/layui.all.js"></script>
<script>
//将所有功能根据parent_id移动到指定模块下
layui.$(".function").each(function () {
var func = layui.$(this);
var parentId = func.data("parent-id");
layui.$("dl[data-node-id=" + parentId + "]").append(func);
})
//刷新折叠菜单
layui.element.render('nav');
</script>
</body>
</html>
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/resources/layui/css/layui.css">
<style>
body{
background-color:#f2f2f2 ;
}
.oa-container{
position:absolute;
width: 400px;
height: 350px;
top: 50%;
left: 50%;
padding: 20px;
margin-left: -200px;
margin-top: -175px;
}
#username,#password{
text-align: center;
font-size:24px;
}
</style>
</head>
<body>
<div class="oa-container">
<h1 style="text-align: center;margin-bottom:20px">OA系统</h1>
<form class="layui-form">
<div class="layui-form-item">
<input type="text" id="username" lay-verify="required" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-item">
<input type="password" id="password" lay-verify="required" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-item">
<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
</div>
</form>
</div>
<script src="/resources/layui/layui.all.js"></script>
<script>
layui.form.on("submit(login)",function(formdata){
console.log(formdata);
layui.$.ajax({
url:"/check_login",
data: formdata.field,
type:"post",
dataType:"json",
success: function (json) {
console.log(json);
if (json.code == "0") {
// layui.layer.msg("登陆成功!");
//跳转url
window.location.href = json.redirect_url;
} else {
layui.layer.msg(json.message);
}
}
})
return false;
})
</script>
</body>
</html>
mappers
<?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.wjb.oa.dao.DepartmentDao">
<select id="selectById" parameterType="Long" resultType="com.wjb.oa.entity.Department">
select * from adm_department where department_id=#{value}
</select>
</mapper>
<?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.wjb.oa.dao.EmployeeDao">
<select id="selectById" parameterType="Long" resultType="com.wjb.oa.entity.Employee">
select * from adm_employee where employee_id=#{value}
</select>
<select id="selectLeader" parameterType="com.wjb.oa.entity.Employee" resultType="com.wjb.oa.entity.Employee">
select * from adm_employee
where
<if test="emp.level < 7">
level=7 and department_id =#{emp.departmentId}
</if>
<if test="emp.level==7">
level=8
</if>
<if test="emp.level==8">
employee_id=#{emp.employeeId}
</if>
</select>
</mapper>
<?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.wjb.oa.dao.LeaveFormDao">
<insert id="insert" parameterType="com.wjb.oa.entity.LeaveForm"
useGeneratedKeys="true" keyProperty="formId" keyColumn="form_id">
INSERT INTO adm_leave_form (employee_id, from_type, start_time, end_time, reason, create_time, state) VALUES (#{employeeId}, #{formType}, #{startTime}, #{endTime}, #{reason}, #{createTime}, #{state})
</insert>
</mapper>
<?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.wjb.oa.dao.NoticeDao">
<insert id="insert" parameterType="com.wjb.oa.entity.Notice"
useGeneratedKeys="true" keyProperty="noticeId" keyColumn="notice_id">
INSERT INTO sys_notice( receiver_id, content, create_time) VALUES (#{receiverId}, #{content}, #{createTime})
</insert>
</mapper>
<?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.wjb.oa.dao.ProcessFlowDao">
<insert id="insert" parameterType="com.wjb.oa.entity.ProcessFlow"
useGeneratedKeys="true" keyProperty="processId" keyColumn="process_id">
INSERT INTO adm_process_flow (form_id,operator_id,action,result,reason,create_time,audit_time,order_no,state,is_last)
VALUES (#{formId}, #{operatorId}, #{action}, #{result}, #{reason}, #{createTime} , #{auditTime} , #{orderNo} , #{state} , #{isLast})
</insert>
</mapper>
service
package com.wjb.oa.service;
import com.wjb.oa.dao.EmployeeDao;
import com.wjb.oa.dao.LeaveFormDao;
import com.wjb.oa.dao.ProcessFlowDao;
import com.wjb.oa.entity.Employee;
import com.wjb.oa.entity.LeaveForm;
import com.wjb.oa.entity.ProcessFlow;
import com.wjb.oa.utils.MybatisUtils;
import java.util.Date;
public class LeaveFormService {
public LeaveForm createLeaveForm(LeaveForm form){
LeaveForm savedform=(LeaveForm)MybatisUtils.excuteUpdate(sqlSession -> {
//1.持久化form表单数据,8级以下员工表单状态为processing,8级(总经理)状态为approved
EmployeeDao employeeDao=sqlSession.getMapper(EmployeeDao.class);
Employee employee=employeeDao.selectById(form.getEmployeeId());
if(employee.getLevel()==8){
form.setState("approved");
}else{
form.setState("processing");
}
LeaveFormDao leaveFormDao = sqlSession.getMapper(LeaveFormDao.class);
leaveFormDao.insert(form);
//2.增加第一条流程数据,说明表单已提交,状态为complete
ProcessFlowDao processFlowDao = sqlSession.getMapper(ProcessFlowDao.class);
ProcessFlow flow1=new ProcessFlow();
flow1.setFormId(form.getFormId());
flow1.setOperatorId(employee.getEmployeeId());
flow1.setAction("apply");
flow1.setCreateTime(new Date());
flow1.setOrderNo(1);
flow1.setState("complete");
flow1.setIsLast(0);
processFlowDao.insert(flow1);
//3.分情况创建其余流程数据
//3.1 7级以下员工,生成部门经理审批任务,请假时间大于72小时,还需生成总经理审批任务
if(employee.getLevel()<7){
Employee dmanager = employeeDao.selectLeader(employee);
ProcessFlow flow2 = new ProcessFlow();
flow2.setFormId(form.getFormId());
flow2.setOperatorId(dmanager.getEmployeeId());
flow2.setAction("audit");
flow2.setCreateTime(new Date());
flow2.setOrderNo(2);
flow2.setState("process");
long diff=form.getEndTime().getTime()-form.getStartTime().getTime();
float hours=diff / (1000 * 60 * 60 * 1f);
if (hours >= BussinessConstants.MANAGER_AUDIT_HOURS) {
flow2.setIsLast(0);
processFlowDao.insert(flow2);
Employee manager = employeeDao.selectLeader(dmanager);
ProcessFlow flow3 = new ProcessFlow();
flow3.setFormId(form.getFormId());
flow3.setOperatorId(manager.getEmployeeId());
flow3.setAction("audit");
flow3.setCreateTime(new Date());
flow3.setState("ready");
flow3.setOrderNo(3);
flow3.setIsLast(1);
processFlowDao.insert(flow3);
} else {
flow2.setIsLast(1);
processFlowDao.insert(flow2);
}
}
//3.2 7级员工,生成总经理审批任务
else if (employee.getLevel() == 7) {
Employee manager=employeeDao.selectLeader(employee);
ProcessFlow flow=new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperatorId(manager.getEmployeeId());
flow.setAction("audit");
flow.setCreateTime(new Date());
flow.setState("process");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
}
//3.3 8级员工,生成总经理审批任务,系统自动通过
else if (employee.getLevel() == 8) {
ProcessFlow flow = new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperatorId(employee.getEmployeeId());
flow.setAction("audit");
flow.setResult("approved");
flow.setReason("自动通过");
flow.setCreateTime(new Date());
flow.setAuditTime(new Date());
flow.setState("complete");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
}
return form;
});
return savedform;
}
}
controller
package com.wjb.oa.controller;
import com.alibaba.fastjson.JSON;
import com.wjb.oa.entity.LeaveForm;
import com.wjb.oa.entity.User;
import com.wjb.oa.service.LeaveFormService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@WebServlet(name = "LeaveFormServlet",urlPatterns = "/leave/*")
public class LeaveFormServlet extends HttpServlet {
private LeaveFormService leaveFormService=new LeaveFormService();
private Logger logger = LoggerFactory.getLogger(LeaveFormServlet.class);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String uri=request.getRequestURI();
String methodName = uri.substring(uri.lastIndexOf("/") + 1);
if(methodName.equals("create")){
this.create(request, response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
private void create(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
User user =(User) session.getAttribute("login_user");
String formType= request.getParameter("formType");
String strStartTime = request.getParameter("startTime");
String strEndTime = request.getParameter("endTime");
String reason = request.getParameter("reason");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
Map result=new HashMap<>();
try {
LeaveForm form = new LeaveForm();
form.setEmployeeId(user.getEmployeeId());
form.setStartTime(sdf.parse(strStartTime));
form.setEndTime(sdf.parse(strEndTime));
form.setFormType(Integer.parseInt(formType));
form.setReason(reason);
form.setCreateTime(new Date());
leaveFormService.createLeaveForm(form);
result.put("code", "0");
result.put("message", "success");
} catch (Exception e) {
logger.error("请假申请异常",e);
result.put("code", e.getClass().getSimpleName());
result.put("message",e.getMessage());
}
String json = JSON.toJSONString(result);
response.getWriter().println(json);
}
}
package com.wjb.oa.controller;
import com.wjb.oa.entity.Department;
import com.wjb.oa.entity.Employee;
import com.wjb.oa.entity.Node;
import com.wjb.oa.entity.User;
import com.wjb.oa.service.EmployeeService;
import com.wjb.oa.service.UserService;
import com.wjb.oa.service.exception.DepartmentService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "IndexServlet",urlPatterns = "/index")
public class IndexServlet extends HttpServlet {
private UserService userService = new UserService();
private EmployeeService employeeService = new EmployeeService();
private DepartmentService departmentService = new DepartmentService();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
//得到当前登录用户对象
User user=(User)session.getAttribute("login_user");
Employee employee= employeeService.selectById(user.getEmployeeId());
List<Node> nodeList=userService.selectNodeByUserId(user.getUserId());
Department department=departmentService.selectById(employee.getDepartmentId());
request.setAttribute("node_list",nodeList);
session.setAttribute("current_employee",employee);
session.setAttribute("current_department",department);
request.getRequestDispatcher("/index.ftl").forward(request,response);
}
}
package com.wjb.oa.controller;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "ForwardServlet",urlPatterns = "/forward/*")
public class ForwardServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri=request.getRequestURI();
String subUri = uri.substring(1);
String page = subUri.substring(subUri.indexOf("/"));
request.getRequestDispatcher(page+".ftl").forward(request,response);
}
}
package com.wjb.oa.controller;
import com.alibaba.fastjson.JSON;
import com.wjb.oa.entity.User;
import com.wjb.oa.service.UserService;
import com.wjb.oa.service.exception.BussinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@WebServlet(name = "LoginServlet" ,urlPatterns = "/check_login")
public class LoginServlet extends HttpServlet {
Logger logger = LoggerFactory.getLogger(LoginServlet.class);
private UserService userService=new UserService();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//接受用户输入
String username = request.getParameter("username");
String password = request.getParameter("password");
Map<String, Object> result = new HashMap<>();
try {
//调用业务逻辑
User user = userService.checkLogin(username, password);
HttpSession session=request.getSession();
session.setAttribute("login_user",user);
result.put("code","0");
result.put("message", "success");
result.put("redirect_url", "/index");
}catch (BussinessException e){
logger.error(e.getMessage(),e);
result.put("code",e.getCode());
result.put("message", e.getMessage());
}catch (Exception e){
logger.error(e.getMessage(),e);
result.put("code",e.getClass().getSimpleName());
result.put("message", e.getMessage());
}
//返回对应结果
String json=JSON.toJSONString(result);
response.getWriter().println(json);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.wjb.oa.controller;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "LogoutServlet",urlPatterns = "/logout")
public class LogoutServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getSession().invalidate();
response.sendRedirect("/login.html");
}
}
正在回答
同学你好,在index中,如下部分应该添加src,如:
script标签中应该增加分号。
另外建议同学将错误描述的更清楚,并且提供更多的报错信息,方便我们根据具体的报错查找问题。
例如:500错误的具体内容是什么?控制台及之后的两个窗口是否有报错。建议同学检查一下。
祝:学习愉快~
相似问题
登录后可查看更多问答,登录/注册
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星