更新时间:2019-01-10 来源:黑马程序员 浏览量:
1 2 | @ApiOperation ( "通过ID删除页面" ) public ResponseResult delete ( String id ) ; |
01 02 03 04 05 06 07 08 09 10 | / / 删除页面 public ResponseResult delete ( String id ) { CmsPage one = this.getById ( id ) ; if ( one! = null ) { / / 删除页面 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 | / * 页面删除 * / 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 ( '确认删除此页面吗?' , '提示' , { } ) . then ( ( ) = > { cmsApi.page_del ( pageId ) . then ( ( res ) = > { if ( res.success ) { this.$ message ( { type : 'success' , message : '删除成功!' } ) ; / / 查询页面 this.query ( ) } else { this.$ message ( { type : ' error ' , message : '删除失败!' } ) ; } } ) } ) } |
1 2 3 4 | / / 添加页面 public CmsPageResult add ( CmsPage cmsPage ) { / / 校验页面是否存在, 根据页面名称、站点Id、页面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 ) ; / / 添加页面主键由spring data 自动生成 cmsPageRepository. save ( cmsPage ) ; / / 返回结果 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 | / / 添加页面 public CmsPageResult add ( CmsPage cmsPage ) { / / 校验cmsPage是否为空 if ( cmsPage = = null ) { / / 抛出异常,非法请求 / / ... } / / 根据页面名称查询(页面名称已在mongodb创建了唯一索引) CmsPage cmsPage 1 = cmsPageRepository.findByPageNameAndSiteIdAndPageWebPath ( cmsPage.getPageName ( ) , cmsPage.getSiteId ( ) , cmsPage.getPageWebPath ( ) ) ; / / 校验页面是否存在,已存在则抛出异常 if ( cmsPage 1 ! = null ) { / / 抛出异常,已存在相同的页面名称 / / ... } cmsPage.setPageId ( null ) ; / / 添加页面主键由spring data 自动生成 CmsPage save = cmsPageRepository. save ( cmsPage ) ; / / 返回结果 CmsPageResult cmsPageResult = new CmsPageResult ( CommonCode.SUCCESS , save ) ; return cmsPageResult; } |