SysDeptRestApi { @PUT @Path("/edit") @SubmarineApi public Response edit(SysDept sysDept) { LOG.info("edit({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = sysDeptMapper.getById(sysDept.getId()); if (dept == null) { return new JsonResponse.Builder<>(Response.Status.OK) .message("Can not found department:" + sysDept.getId()).success(false).build(); } sysDeptMapper.updateBy(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message("Update department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK).success(true) .message("Update department successfully!").build(); } @Inject  SysDeptRestApi(); @GET @Path("/tree") @SubmarineApi // Query all departments and respond to the front end in tree structure data format Response tree(@QueryParam("deptCode") String likeDeptCode,
                       @QueryParam("deptName") String likeDeptName); @GET @Path("/queryIdTree") @SubmarineApi Response queryIdTree(@QueryParam("disableDeptCode") String disableDeptCode); @POST @Path("/add") @SubmarineApi Response add(SysDept sysDept); @PUT @Path("/edit") @SubmarineApi Response edit(SysDept sysDept); @PUT @Path("/resetParentDept") @SubmarineApi Response resetParentDept(); @DELETE @Path("/delete") @SubmarineApi Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted); @DELETE @Path("/deleteBatch") @SubmarineApi Response deleteBatch(@QueryParam("ids") String ids); @DELETE @Path("/remove") @SubmarineApi Response remove(String id); static final String SHOW_ALERT; }
@Test public void editTest() { SysDept deptA = new SysDept("A", "deptA"); Response response = sysDeptRestApi.add(deptA); CommonDataTest.assertDeptResponseSuccess(response); deptA.setDeptCode("A-modify"); deptA.setDeptName("deptA-modify"); deptA.setParentCode("A-modify"); deptA.setDeleted(5); deptA.setDescription("desc"); deptA.setSortOrder(9); response = sysDeptRestApi.edit(deptA); CommonDataTest.assertDeptResponseSuccess(response); JsonResponse<ListResult<SysDeptTree>> response4 = CommonDataTest.queryDeptTreeList(); SysDeptTree sysDeptTree = response4.getResult().getRecords().get(0); assertEquals(sysDeptTree.getDeptCode(), deptA.getDeptCode()); assertEquals(sysDeptTree.getDeptName(), deptA.getDeptName()); assertEquals(sysDeptTree.getParentCode(), deptA.getParentCode()); assertEquals(sysDeptTree.getParentName(), "deptA-modify"); assertEquals(sysDeptTree.getDeleted(), deptA.getDeleted()); assertEquals(sysDeptTree.getDescription(), deptA.getDescription()); assertEquals(sysDeptTree.getSortOrder(), deptA.getSortOrder()); }