• 阶段5 3.微服务项目【学成在线】_day03 CMS页面管理开发_09-修改页面-服务端-接口开发





    需要写两个接口

    api的接口内定义两个方法。修改的地方单独传了id

        @ApiOperation("根据页面id查询页面信息")
        public CmsPage findById(String id);
    
        @ApiOperation("修改页面")
        public CmsPageResult edit(String id,CmsPage cmsPage);

    编写Service


    先查询要修改的数据是否存在 




    //根据页面id查询页面
        public CmsPage getById(String id){
            Optional<CmsPage> optional = cmsPageRepository.findById(id);
            if(optional.isPresent()){
                CmsPage cmsPage=optional.get();
                return cmsPage;
            }
            return null;
        }
    
        public CmsPageResult update(String id,CmsPage cmsPage){
            //根据id 从数据库查询页面
            CmsPage one=this.getById(id);
            if(one!=null){
                //设置更新数据
                //设置要修改的数据
                //更新模板id
                one.setTemplateId(cmsPage.getTemplateId());
                one.setSiteId(cmsPage.getSiteId());
                one.setPageAliase(cmsPage.getPageAliase());
                one.setPageName(cmsPage.getPageName());
                one.setPageWebPath(cmsPage.getPageWebPath());
                //更新屋里路径
                one.setPagePhysicalPath(cmsPage.getPagePhysicalPath());
                cmsPageRepository.save(one);
                return new CmsPageResult(CommonCode.SUCCESS,one);
            }
            return new CmsPageResult(CommonCode.FAIL,null);
        }

    controller



    修改的数据要json提交。所以这里用@RequestBody

     @Override
        @GetMapping("/get/{id}")
        public CmsPage findById(@PathVariable String id) {
            return pageService.getById(id);
        }
    
        @Override
        @PutMapping("/edit/{id}")
        public CmsPageResult edit(@PathVariable String id,@RequestBody CmsPage cmsPage) {
    
            return pageService.update(id,cmsPage);
        }



    修改数据







     

  • 相关阅读:
    Objective Evaluation Index of image
    MATLAB奔溃仅左上角显示关闭界面X
    论文修改指南之发表
    科研第一步:文献查找和下载
    实习项目1-串口IP升级调试
    FPGA驱动LCD显示红绿蓝彩条
    tw9912配置使用
    BT.656视频信号解码
    色彩空间转换 rgb转ycbcr422/ycbcr422转rgb
    xilinx VDMA IP核使用
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11569948.html
Copyright © 2020-2023  润新知