Sling或CQ5中,REST的选择器的规则

选择器优先匹配文件夹

1. 一个选择器的情况。

   比如一个JCR的节点,映射到/apps/training-site/components/job

   

    访问 http://localhost:4502/content/training-site/en/job.print.html

    将会使用job/print/GET.jsp来渲染,查找顺序如下

    job/print/print.html.jsp

    job/print.html.jsp

    job/print/html.jsp

    job/print/print.jsp

     job/print.jsp

    job/print/GET.jsp (此处print选择器查找完成,如果没有找到开始找job)

    job/html.jsp

    job/job.jsp

    job/GET.jsp

    NULL


2. 多个选择器的情况

   Sling或CQ5中,REST的选择器的规则_第1张图片

Sling或CQ5中,REST的选择器的规则_第2张图片

    比如:http://localhost:4502/content/training-site/en/jobs.print.a4.a.html

    按以下匹配

    jobs/print/a4/a/a.html.jsp

    jobs/print/a4/a.html.jsp

    jobs/print/a4/a/html.jsp

    jobs/print/a4/a/a.jsp

    jobs/print/a4/a.jsp

    jobs/print/a4/a/GET.jsp(选择器a找完)

    jobs/print/a4/html.jsp

    jobs/print/a4.html.jsp(a4.a.html.jsp没有被选择,感觉很奇怪)

    jobs/print/a4.jsp(a4找完)

    jobs/print.html.jsp(print.a4.html.jsp没有被选择,我认为应该只关注当前选择器)

    jobs/print.jsp

    jobs/html.jsp

    jobs/jobs.jsp

    jobs/GET.jsp


3. 补充一个选择器的情况

/content/training-site/en/jobs 使用 /apps/training/components/jobs/ 来render.

访问 /content/training-site/en/jobs.print.a4.html 将按照以下顺序查找

1./apps/training/components/jobs/print/a4/a4.html.jsp

2./apps/training/components/jobs/print/a4.html.jsp

3./apps/training/components/jobs/print/a4/html.jsp

4./apps/training/components/jobs/print/a4/a4.jsp

5./apps/training/components/jobs/print/a4.jsp(a4选择器结束)


6./apps/training/components/jobs/print/print.html.jsp

7./apps/training/components/jobs/print.html.jsp

8./apps/training/components/jobs/print/html.jsp

9./apps/training/components/jobs/print/print.jsp

10./apps/training/components/jobs/print.jsp (print 选择器结束)

11./apps/training/components/jobs/html.jsp

12./apps/training/components/jobs/jobs.jsp


4. 继续补充一个没有选择器的情况

/content/training-site/en/jobs 使用 /apps/training/components/myjobs/ 来render.

访问 /content/training-site/en/jobs.html 将会找怎样的脚本来渲染呢?会不会是下面这样

1./apps/training/components/myjobs/jobs/jobs.html.jsp

2. /apps/training/components/myjobs/jobs.html.jsp

3./apps/training/components/myjobs/jobs/html.jsp

4./apps/training/components/myjobs/jobs/jobs.jsp

5./apps/training/components/myjobs/jobs.jsp

6./apps/training/components/myjobs/html.jsp

7./apps/training/components/myjobs/myjobs.jsp

错了,sling/CQ5不会把jobs看成是选择器,所以下面的才是正确的,先找后缀,再找名称

6./apps/training/components/myjobs/html.jsp

7./apps/training/components/myjobs/myjobs.jsp


你可能感兴趣的:(REST,Restful,cq5,Sling)