admin fault
This commit is contained in:
parent
7c889fed2a
commit
dd2d0d7263
@ -0,0 +1,47 @@
|
||||
package cn.edu.cqwu.repair.controller.admin;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.FaultDao;
|
||||
import cn.edu.cqwu.repair.util.AppInit;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import cn.edu.cqwu.repair.entity.Fault;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
*/
|
||||
@Controller
|
||||
public class AdminFaultController {
|
||||
private final FaultDao faultDao;
|
||||
|
||||
public AdminFaultController(FaultDao faultDao) {
|
||||
this.faultDao = faultDao;
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/fault/delete.do")
|
||||
public String deleteFault(int faultId, Model model, HttpServletRequest request) {
|
||||
if (faultDao.deleteFault(faultId) > 0) {
|
||||
model.addAttribute("faultMess", "删除成功");
|
||||
AppInit.initFault(request.getServletContext(), faultDao);
|
||||
} else {
|
||||
model.addAttribute("faultMess", "删除失败");
|
||||
}
|
||||
return "/admin/fault";
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/fault/add.do")
|
||||
public String addFault(String faultName, Model model, HttpServletRequest request) {
|
||||
Fault fault = new Fault();
|
||||
fault.setFaultName(faultName);
|
||||
if (faultDao.add(fault) > 0) {
|
||||
model.addAttribute("faultMess", "添加成功");
|
||||
AppInit.initFault(request.getServletContext(), faultDao);
|
||||
} else {
|
||||
model.addAttribute("faultMess", "添加失败");
|
||||
}
|
||||
return "/admin/fault";
|
||||
}
|
||||
}
|
14
src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java
Normal file
14
src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java
Normal file
@ -0,0 +1,14 @@
|
||||
package cn.edu.cqwu.repair.dao;
|
||||
|
||||
import cn.edu.cqwu.repair.entity.Fault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
*/
|
||||
public interface FaultDao {
|
||||
int add(Fault fault);
|
||||
ArrayList<Fault> findAllFault();
|
||||
int deleteFault(int id);
|
||||
}
|
37
src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java
Normal file
37
src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java
Normal file
@ -0,0 +1,37 @@
|
||||
package cn.edu.cqwu.repair.dao.impl;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.FaultDao;
|
||||
import cn.edu.cqwu.repair.db.ConnectionFactory;
|
||||
import cn.edu.cqwu.repair.entity.Fault;
|
||||
import cn.edu.cqwu.repair.entity.mapper.FaultMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static cn.edu.cqwu.repair.entity.table.FaultTableDef.FAULT;
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
*/
|
||||
@Component
|
||||
public class FaultDaoImpl implements FaultDao {
|
||||
private static final FaultMapper MAPPER = ConnectionFactory.getMapper(FaultMapper.class);
|
||||
|
||||
@Override
|
||||
public int add(Fault fault) {
|
||||
return MAPPER.insert(fault);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Fault> findAllFault() {
|
||||
return (ArrayList<Fault>) MAPPER.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteFault(int id) {
|
||||
QueryWrapper qw = new QueryWrapper();
|
||||
qw.where(FAULT.FAULT_ID.eq(id));
|
||||
return MAPPER.deleteByQuery(qw);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.DeviceDao;
|
||||
import cn.edu.cqwu.repair.dao.FaultDao;
|
||||
import cn.edu.cqwu.repair.util.AppInit;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
@ -24,6 +25,8 @@ public class MyServletContextListener extends AppInit implements ServletContextL
|
||||
if (context != null) {
|
||||
DeviceDao deviceDao = context.getBean(DeviceDao.class);
|
||||
initDevice(application, deviceDao);
|
||||
FaultDao faultDao = context.getBean(FaultDao.class);
|
||||
initFault(application, faultDao);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.edu.cqwu.repair.util;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.DeviceDao;
|
||||
import cn.edu.cqwu.repair.dao.FaultDao;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@ -8,6 +9,10 @@ import javax.servlet.ServletContext;
|
||||
* @author xtaod
|
||||
*/
|
||||
public class AppInit {
|
||||
public static void initFault(ServletContext servletContext, FaultDao faultDao) {
|
||||
servletContext.setAttribute("faults", faultDao.findAllFault());
|
||||
}
|
||||
|
||||
public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) {
|
||||
servletContext.setAttribute("device", deviceDao.findAllDevice());
|
||||
}
|
||||
|
79
src/main/webapp/admin/fault.jsp
Normal file
79
src/main/webapp/admin/fault.jsp
Normal file
@ -0,0 +1,79 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: xtaod
|
||||
Date: 2024/5/15
|
||||
Time: 下午9:54
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ page isELIgnored="false" %>
|
||||
<c:set var="title" value="报修类型维护"/>
|
||||
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>${title}</title>
|
||||
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
|
||||
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/entry.css" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<main class="d-flex flex-nowrap">
|
||||
<%@ include file="../includes/header.jsp" %>
|
||||
|
||||
<main class="form-signin w-100 m-auto scrollspy" style="min-width: 800px">
|
||||
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
|
||||
|
||||
<h1 class="h3 mb-3 fw-normal">已添加的报修类型列表</h1>
|
||||
<c:if test="${not empty requestScope.faultMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.faultMess}
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">故障序号</th>
|
||||
<th scope="col">故障名称</th>
|
||||
<th scope="col">删除故障</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${applicationScope.faults}" var="fault" varStatus="rows">
|
||||
<tr>
|
||||
<td>${rows.count}</td>
|
||||
<td>${fault.faultName}</td>
|
||||
<td><a href="${webroot}/admin/fault/delete.do?faultId=${fault.faultId}">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h1 class="h3 mb-3 fw-normal">添加报修类型</h1>
|
||||
<c:if test="${not empty requestScope.addMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.addMess}
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<form action="${webroot}/admin/fault/add.do" method="post">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">故障名称</span>
|
||||
<input type="text" class="form-control" name="faultName" id="faultName" required>
|
||||
</div>
|
||||
<input class="btn btn-primary w-100 py-2" type="submit" id="submit">
|
||||
<br/><br/>
|
||||
<input class="btn btn-primary w-100 py-2" type="reset" value="重置">
|
||||
<br/><br/>
|
||||
</form>
|
||||
</main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -47,8 +47,8 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="${webroot}/admin/state.jsp" class="nav-link link-body-emphasis" aria-current="page">
|
||||
>> 报修类型管理
|
||||
<a href="${webroot}/admin/fault.jsp" class="nav-link link-body-emphasis" aria-current="page">
|
||||
>> 报修类型维护
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
Loading…
Reference in New Issue
Block a user