学成在线 第3天 讲义-CMS页面管理开发二

新增页面 
2.1 新增页面接口定义 
1、定义响应模型

@Data
public class CmsPageResult extends ResponseResult {
CmsPage cmsPage;
public CmsPageResult(ResultCode resultCode,CmsPage cmsPage) {
super(resultCode);
this.cmsPage
=
cmsPage;
}
}

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

@ApiOperation(
"
添加页面
"
)
public CmsPageResult add(CmsPage cmsPage);

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

public interface CmsPageRepository extends MongoRepository<CmsPage,String> {
//根据页面名称、站点id、页面访问路径查询
CmsPage findByPageNameAndSiteIdAndPageWebPath(String pageName,String siteId,String
pageWebPath);
。。。

2、使用 CmsPageRepository提供的save方法 。 
2.2.3 Service
//添加页面

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

//添加页面 

@Override
@PostMapping(
"
/add
"
)
public CmsPageResult add(@RequestBody CmsPage cmsPage) {
return pageService.add(cmsPage);
}

2.2.5 接口测试 
使用postman测试

post请求:http://localhost:31001/cms/page/add 
请求内容为json数据,测试数据如下:

{[/size][/font]
[font=微软雅黑][size=3]"
dataUrl
"
:
"
string
"
,
"
htmlFileId
"
:
"
string
"
,
"
pageAliase
"
:
"
string
"
,
"
pageCreateTime
"
:
"
2018
‐
06
‐
11T02:01:25.667Z
"
,
"
pageHtml
"
:
"
string
"
,
"
pageName
"
:
"
测试页面
"
,
"
pageParameter
"
:
"
string
"
,
"
pagePhysicalPath
"
:
"
string
"
,
"
pageStatus
"
:
"
string
"
,
"
pageTemplate
"
:
"
string
"
,
"
pageType
"
:
"
string
"
,
"
pageWebPath
"
:
"
string
"
,
"
siteId
"
:
"
string
"
,
"
templateId
"
:
"
string
"
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值