需要写两个接口

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

 

    @ApiOperation("根据页面id查询页面信息")
    public CmsPage findById(String id);

    @ApiOperation("修改页面")
    public CmsPageResult edit(String id,CmsPage cmsPage);

 

 


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

 

//根据页面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);
    }

 



修改数据



 

相关文章:

  • 2021-08-14
  • 2021-09-07
  • 2021-10-13
  • 2021-06-12
  • 2021-11-03
  • 2021-07-31
  • 2021-07-15
  • 2021-08-30
猜你喜欢
  • 2021-10-14
  • 2022-01-02
  • 2022-01-14
  • 2021-09-20
  • 2021-07-16
  • 2022-01-26
  • 2022-01-01
相关资源
相似解决方案