play 内置标签


标签使用说明

1 标签皆可应用在页面和js代码中
2 使用?.可避免当对象为空时出现NullPointerException导致页面渲染失败
3 取值使用${}格式

${flash?.errCode}//从flash对象中取值
${jumpUrl}//action返回页面参数
${session?.user?.userName}//从session中获取用户名

4 可通过指定全限定类名直接调用静态方法、字段等

${utils.DateUtils?.getTime()}//通过调用DateUtils中的静态方法获取当前时间
${utils.DateUtils?.FORMAT_YMD}//获取DateUtils中的字段值

5 闭合标签#{a}首页#{/a},非闭合标签#{input /}
6 注释使用%{注释文本}%


常用标签

  • a:链接到router表中对应的路由
#{a @Application.index()}首页#{/a} 
[首页](“@{Application.index()}”)
[首页](“application/index”)
  • authenticityToken: 用来生成一个包含token信息的可以放到任何form的隐藏域,用来防止跨站点的请求伪造攻击。后台form提交路由函数中直接调用checkAuthenticity(),校验不通过会跳转到默认的错误页面。
#{authenticityToken /} 
<input type="hidden" name="authenticityToken" value="1c6d92fed96200347f06b7c5e1a3a28fa258ef7c">   
  • doLayout: 模板继承标签,子元素通过#{extends '父元素相对路径'/}来进行页面的嵌套
<!--父页面文件common/common.html-->
<div class="container">
    <div class="header">头部</div>
    <!--此处用来引用子页面,类似jsp中的include标签-->
    #{doLayout /}
    <div class="footer">底部</div>
</div>
  • extends:继承父标签
<!--子页面front/index.html-->
#{extends 'common/common.html' /}
<div class="child">子页面内容区</div>
  • if...else:用来在页面中进行逻辑判断,if可单用也可配合使用,可用页面js中
#{if user==null}登录#{/if}
#{elseif user!=null && !user?.auther}认证#{/elseif}
#{else}登录成功#{/else}
  • list:用来迭代后台集合数据,items指定集合数据,as指定别名
#if{userList!=null && userList.size()>0}
#{list items:userList,as:'user'}
    <tr>
        <td>${user_index}</td>//本次迭代的索引值
        <td>${(page?.currPage - 1)*page?.pageSize+_index}</td>//分页数据中的索引值
        <td>${user?.name}</td>
        ...
    </tr>
#{/list}
#{/if}
或者
#if{userList!=null && userList.size()>0}
#{list items:userList}
    <tr>
        <td>${user_index}</td>//本次迭代的索引值
        <td>${(page?.currPage - 1)*page?.pageSize+_index}</td>//分页数据中的索引值
        <td>${_?.name}</td>
        ...
    </tr>
#{/list}
#{/if}
  • %{}:代码块,可用来直接编写源代码,可直接在页面通过${}引用
%{utils.DateUtils date = new utils.DateUtils();}%
# ${date?.currentTime()?.format('yyyy-MM-dd HH:mm:ss')
# ${constants.Constants.money?.format('###,##0.00')}
# ${constants.Constants.money?.formatCurrency('CNY')}
输入图片说明
输入图片说明
  • get|set
#{set title:'标题'/}
#{get 'title'/}
  • @{‘’}:静态资料导入标签
    <link href="@{'/public/stylesheets/main.css'}" rel="stylesheet"/> <link href='/public/stylesheets/main.css' rel="stylesheet"/>

  • form:表单
    #{form @login(), method:'POST', id:'sub'} #{/form}

<form action="/indexaction/login?x-http-method-override=POST" method="post" accept-charset="utf-8" enctype="application/x-www-form-urlencoded" id="sub">
<input type="hidden" name="authenticityToken" value="84aec43e817adbb56496c312236b1e49ad250efd">
</form>
  • include:类似jsp中的include标签
    #{include 'Application/index.html'/}

标签内置常用函数

  • format():格式化日期、金额等
${money?.format('###,##0.00')}
${money?.formatCurrency('CNY')}
${date?.format('yyyy-MM-dd HH:mm:ss')}
  • raw():以html格式显示
    ${content?.raw()}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • title: 风格指南type: style-guide 这里是官方的 Vue 特有代码的风格指南。如果在工程中使...
    ChenyuMa阅读 1,101评论 1 1
  • web_url 语法: Int Web_url(constchar *name, const char * url...
    社会主义顶梁鹿阅读 852评论 0 0
  • FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1...
    年轻小伙程序员阅读 3,057评论 0 5
  • d3 (核心部分)选择集d3.select - 从当前文档中选择一系列元素。d3.selectAll - 从当前文...
    谢大见阅读 3,493评论 1 4
  • 浏览器与服务器的基本概念 浏览器(安装在电脑里面的一个软件) 作用: ①将网页内容渲染呈现给用户查看。 ②让用户通...
    云还灬阅读 1,158评论 0 0