A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

2 新增页面 2.1 新增页面接口定义
1、定义响应模型
[AppleScript] 纯文本查看 复制代码
@Data 
public class CmsPageResult extends ResponseResult {  
   CmsPage cmsPage;  
   public CmsPageResult(ResultCode resultCode,CmsPage cmsPage) {     
    super(resultCode);       
  this.cmsPage = cmsPage;   
  } 
}

2、定义添加Api 在api工程中添加接口:

[AppleScript] 纯文本查看 复制代码
@ApiOperation("添加页面") 
public CmsPageResult add(CmsPage cmsPage);

2.2 新增页面服务端开发
2.2.1 页面唯一索引
在cms_page集中上创建页面名称、站点Id、页面webpath为唯一索引   2.2.2 Dao
1、添加根据页面名称、站点Id、页面webpath查询页面方法,此方法用于校验页面是否存在

[AppleScript] 纯文本查看 复制代码
public interface CmsPageRepository extends MongoRepository<CmsPage,String> { 
    //根据页面名称、站点id、页面访问路径查询   
  CmsPage findByPageNameAndSiteIdAndPageWebPath(String pageName,String siteId,String  pageWebPath);  
   。。

2、使用 CmsPageRepository提供的save方法 。 2.2.3 Service
[AppleScript] 纯文本查看 复制代码
 //添加页面   
  public CmsPageResult add(CmsPage cmsPage){ //校验页面是否存在,
根据页面名称、站点Id、页面webpath查询       
           CmsPage cmsPage1 = 
 cmsPageRepository.findByPageNameAndSiteIdAndPageWebPath(cmsPage.getPageName(), 
 cmsPage.getSiteId(), cmsPage.getPageWebPath());      
    if(cmsPage1==null){         
    cmsPage.setPageId(null);//添加页面主键由spring data 自动生成      
       cmsPageRepository.save(cmsPage);       
      //返回结果     
        CmsPageResult cmsPageResult = new CmsPageResult(CommonCode.SUCCESS,cmsPage);      
       return cmsPageResult;       
  }    
     return new CmsPageResult(CommonCode.FAIL,null); 
    }

2.2.4 Controller
[AppleScript] 纯文本查看 复制代码
 //添加页面  
   @Override 
    @PostMapping("/add")  
   public CmsPageResult add(@RequestBody CmsPage cmsPage) {  
       return pageService.add(cmsPage);  
   }




0 个回复

您需要登录后才可以回帖 登录 | 加入黑马