已添加的报修区域列表
+区域序号 | +区域名称 | +操作 | +删除 | +
---|---|---|---|
${rows.count} | +${address.addressName} | +修改 + | 删除 + | +
- | +---- ${address0.addressName} | +修改 + | 删除 + | +
修改区域
+添加区域
++ +
+ +
diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java new file mode 100644 index 0000000..5218577 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java @@ -0,0 +1,92 @@ +package cn.edu.cqwu.repair.controller.admin; + +import cn.edu.cqwu.repair.dao.AddressDao; +import cn.edu.cqwu.repair.entity.Address; +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 javax.servlet.http.HttpServletRequest; + +/** + * @author xtaod + */ +@Controller +public class AdminAddressController { + private final AddressDao addressDao; + + public AdminAddressController(AddressDao addressDao) { + this.addressDao = addressDao; + } + + @RequestMapping("/admin/address/delete.do") + public String deleteAddress(int addressId, Model model, HttpServletRequest request) { + if (addressDao.deleteAddress(addressId) > 0) { + model.addAttribute("addressMess", "删除成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addressMess", "删除失败"); + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/add.do") + public String addAddress(String addressName, int parentId, Model model, HttpServletRequest request) { + Address address = new Address(); + address.setAddressName(addressName); + if (parentId == 0) { + address.setIsParent(1); + address.setParentId(null); + } else { + address.setIsParent(0); + address.setParentId(parentId); + } + if (addressDao.add(address) > 0) { + model.addAttribute("addMess", "添加成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addMess", "添加失败"); + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/update.do") + public String updateAddress(int addressId, String addressName, int parentId, Model model, HttpServletRequest request) { + Address address = addressDao.findAddressById(addressId); + if (address == null) { + model.addAttribute("addMess", "未找到该故障,请重试"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + address.setAddressName(addressName); + if (parentId == 0) { + address.setIsParent(1); + address.setParentId(null); + } else { + address.setIsParent(0); + address.setParentId(parentId); + } + if (addressDao.update(address) > 0) { + model.addAttribute("addMess", "修改成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addMess", "修改失败"); + } + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/query.do") + public String queryAddress(int addressId, Model model, HttpServletRequest request) { + Address address = addressDao.findAddressById(addressId); + if (address == null) { + model.addAttribute("addressMess", "未找到该故障,请重试"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("updateAddressId", address.getAddressId()); + model.addAttribute("updateAddressName", address.getAddressName()); + model.addAttribute("updateAddressParentId", address.getParentId()); + } + return "/admin/address"; + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java index 83fdb75..9a4767e 100644 --- a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java @@ -1,13 +1,12 @@ package cn.edu.cqwu.repair.controller.admin; import cn.edu.cqwu.repair.dao.FaultDao; +import cn.edu.cqwu.repair.entity.Fault; 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; /** @@ -37,10 +36,41 @@ public class AdminFaultController { Fault fault = new Fault(); fault.setFaultName(faultName); if (faultDao.add(fault) > 0) { - model.addAttribute("faultMess", "添加成功"); + model.addAttribute("addMess", "添加成功"); AppInit.initFault(request.getServletContext(), faultDao); } else { - model.addAttribute("faultMess", "添加失败"); + model.addAttribute("addMess", "添加失败"); + } + return "/admin/fault"; + } + + @RequestMapping("/admin/fault/update.do") + public String updateFault(int faultId, String faultName, Model model, HttpServletRequest request) { + Fault fault = faultDao.findFaultById(faultId); + if (fault == null) { + model.addAttribute("addMess", "未找到该故障,请重试"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + fault.setFaultName(faultName); + if (faultDao.update(fault) > 0) { + model.addAttribute("addMess", "修改成功"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + model.addAttribute("addMess", "修改失败"); + } + } + return "/admin/fault"; + } + + @RequestMapping("/admin/fault/query.do") + public String queryFault(int faultId, Model model, HttpServletRequest request) { + Fault fault = faultDao.findFaultById(faultId); + if (fault == null) { + model.addAttribute("faultMess", "未找到该故障,请重试"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + model.addAttribute("updateFaultId", fault.getFaultId()); + model.addAttribute("updateFaultName", fault.getFaultName()); } return "/admin/fault"; } diff --git a/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java b/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java new file mode 100644 index 0000000..b40f2d6 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java @@ -0,0 +1,17 @@ +package cn.edu.cqwu.repair.dao; + +import cn.edu.cqwu.repair.entity.Address; + +import java.util.ArrayList; + +/** + * @author xtaod + */ +public interface AddressDao { + int add(Address address); + int update(Address address); + ArrayList
findAllAddress(); + ArrayList findAddressByParent(int parent); + int deleteAddress(int id); + Address findAddressById(int id); +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java index d6f8b14..a47af04 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java @@ -9,6 +9,8 @@ import java.util.ArrayList; */ public interface FaultDao { int add(Fault fault); + int update(Fault fault); ArrayList区域序号 | +区域名称 | +操作 | +删除 | +
---|---|---|---|
${rows.count} | +${address.addressName} | +修改 + | 删除 + | +
- | +---- ${address0.addressName} | +修改 + | 删除 + | +