Java的新项目学成在线笔记-day9(十三)

4.3.2 模板测试 
使用test-freemarker工程测试模板
编写模板过程采用test-freemarker工程测试模板。 将course.ftl拷贝到test-freemarker工程的resources/templates下,并在test-freemarker工程的controller中添加 测试方法

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

5

6

//课程详情页面测试

 @RequestMapping("/course") public String course(Map<String,Object> map){  

  ResponseEntity<Map> forEntity =

  restTemplate.getForEntity("http://localhost:31200/course/courseview/4028e581617f945f01617f9dabc4 0000", Map.class);   

 Map body = forEntity.getBody();  

  map.put("model",body);     return "course"; }


注意:上边的测试页面不显示样式,原因是页面通过SSI包含了页面头,而使用test-freemarker工程无法加载页 头,测试模板主要查看html页面内容是否正确,待课程预览时解决样式不显示问题。
  4.3.3 模板保存 
模板编写并测试通过后要在数据库保存:
1、模板信息保存在xc_cms数据库(mongodb)的cms_template表
2、模板文件保存在mongodb的GridFS中。  
第一步:将模板文件上传到GridFS中 由于本教学项目中模板管理模块没有开发,所以我们使用Junit代码向GridFS中保存:
 

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

5

6

7

8

//文件存储2

 @Test  public void testStore2() throws FileNotFoundException { 

    File file = new File("C:\\Users\\admin\\Desktop\\course.ftl")

    FileInputStream inputStream = new FileInputStream(file)

    //保存模版文件内容   

  GridFSFile gridFSFile = gridFsTemplate.store(inputStream, "课程详情模板文件","");   

  String fileId = gridFSFile.getId().toString();  

   System.out.println(fileId)}


保存成功需要记录模板文件的id,即上边代码中的fileId。
第二步:向cms_template表添加模板记录(请不要重复添加)
使用Studio 3T连接mongodb,向cms_template添加记录:
 

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

5

{ 

 "_class" : "com.xuecheng.framework.domain.cms.CmsTemplate", 

  "siteId" : "5a751fab6abb5044e0d19ea1", 

  "templateName" : "课程详情页面正式模板",

   "templateFileId" : "这里填写上边代码返回的模板文件id"


4.3.4 其它模板 
除了课程详情主页面需要设计模板所有静态化的页面都要设计模板,如下:
教育机构页面模板、教师信息页面模板、课程统计信息json模板、教育机构统计信息json模板。
本项目我们实现课程详情主页面模板的制作和测试,其它页面模板的开发参考课程详情页面去实现。

猜你喜欢

转载自blog.csdn.net/czbkzmj/article/details/89632562
今日推荐