更新時(shí)間:2019-01-10 來源:黑馬程序員 瀏覽量:
1 2 | @ApiOperation ( "通過ID刪除頁(yè)面" ) public ResponseResult delete ( String id ) ; |
01 02 03 04 05 06 07 08 09 10 | / / 刪除頁(yè)面 public ResponseResult delete ( String id ) { CmsPage one = this.getById ( id ) ; if ( one! = null ) { / / 刪除頁(yè)面 cmsPageRepository.deleteById ( id ) ; return new ResponseResult ( CommonCode.SUCCESS ) ; } return new ResponseResult ( CommonCode.FAIL ) ; } |
1 2 3 4 | @DeleteMapping ( "/del/{id}" ) / / 使用http的 delete 方法完成崗位操作 public ResponseResult delete ( @PathVariable ( "id" ) String id ) { return pageService. delete ( id ) ; } |
1 2 3 | / * 頁(yè)面刪除 * / export const page_del = id = > { return http.requestDelete ( apiUrl + ' / cms / page / del / ' + id ) } |
01 02 03 04 05 06 07 08 09 10 11 12 | < el‐table‐ column label = "操作" width = "120" > < template slot‐scope = "page" > < el‐ button size = "small" type = "text" @click = "edit(page.row.pageId)" > 編輯 < / el‐ button > < el‐ button size = "small" type = "text" @click = "del(page.row.pageId)" > 刪除 < / el‐ button > < / template > < / el‐table‐ column > |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 | / / 刪除 del : function ( pageId ) { this.$confirm ( '確認(rèn)刪除此頁(yè)面嗎?' , '提示' , { } ) . then ( ( ) = > { cmsApi.page_del ( pageId ) . then ( ( res ) = > { if ( res.success ) { this.$ message ( { type : 'success' , message : '刪除成功!' } ) ; / / 查詢頁(yè)面 this.query ( ) } else { this.$ message ( { type : ' error ' , message : '刪除失敗!' } ) ; } } ) } ) } |
1 2 3 4 | / / 添加頁(yè)面 public CmsPageResult add ( CmsPage cmsPage ) { / / 校驗(yàn)頁(yè)面是否存在, 根據(jù)頁(yè)面名稱、站點(diǎn)Id、頁(yè)面webpath查詢 CmsPage cmsPage 1 = |
01 02 03 04 05 06 07 08 09 10 11 | cmsPageRepository.findByPageNameAndSiteIdAndPageWebPath ( cmsPage.getPageName ( ) , cmsPage.getSiteId ( ) , cmsPage.getPageWebPath ( ) ) ; if ( cmsPage 1 = = null ) { cmsPage.setPageId ( null ) ; / / 添加頁(yè)面主鍵由spring data 自動(dòng)生成 cmsPageRepository. save ( cmsPage ) ; / / 返回結(jié)果 CmsPageResult cmsPageResult = new CmsPageResult ( CommonCode.SUCCESS , cmsPage ) ; return cmsPageResult; } return new CmsPageResult ( CommonCode.FAIL , null ) ; } |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | / / 添加頁(yè)面 public CmsPageResult add ( CmsPage cmsPage ) { / / 校驗(yàn)cmsPage是否為空 if ( cmsPage = = null ) { / / 拋出異常,非法請(qǐng)求 / / ... } / / 根據(jù)頁(yè)面名稱查詢(頁(yè)面名稱已在mongodb創(chuàng)建了唯一索引) CmsPage cmsPage 1 = cmsPageRepository.findByPageNameAndSiteIdAndPageWebPath ( cmsPage.getPageName ( ) , cmsPage.getSiteId ( ) , cmsPage.getPageWebPath ( ) ) ; / / 校驗(yàn)頁(yè)面是否存在,已存在則拋出異常 if ( cmsPage 1 ! = null ) { / / 拋出異常,已存在相同的頁(yè)面名稱 / / ... } cmsPage.setPageId ( null ) ; / / 添加頁(yè)面主鍵由spring data 自動(dòng)生成 CmsPage save = cmsPageRepository. save ( cmsPage ) ; / / 返回結(jié)果 CmsPageResult cmsPageResult = new CmsPageResult ( CommonCode.SUCCESS , save ) ; return cmsPageResult; } |