zoukankan      html  css  js  c++  java
  • 阶段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);
        }



    修改数据







     

  • 相关阅读:
    如何快速建立自己的知识体系
    让你的网站变成灰色
    Java多线程-锁升级
    冰河正则大全
    Win硬盘/U盘设置图片
    MySQL——三范式
    MySQL——事务
    MySQL_explain
    HDFS的一些常用指令
    Hadoop集群的搭建准备
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11569948.html
Copyright © 2011-2022 走看看