在一次项目中使用到Beetl模板,整理几个日期使用场景,以便后期查阅!
变量定义
<%
var a = 3;
var b = 3,c = "abc",d=true,e=null;
var f = [1,2,3];
var g = {key1:a,key2:c};
var i = a+b;
%>
更多参见:http://ibeetl.com/guide/#/beetl/basic?id=%E4%B8%B4%E6%97%B6%E5%8F%98%E9%87%8F%E5%AE%9A%E4%B9%89
字符串相关
- strutil.startWith ${ strutil.startWith("hello","he")} 输出是true
- strutil.endWith ${ strutil.endWith("hello","o")} 输出是true
- strutil.length ${ strutil. length ("hello")},输出是5
- strutil.subString ${ strutil.subString ("hello",1)},输出是"ello"
- strutil.subStringTo ${ strutil.subStringTo ("hello",1,2)},输出是"e"
- strutil.split ${ strutil.split ("hello,joeli",",")},参数第一个是字符串,第二个是正则表达式。输出是数组:返回第一个是"hello",第二个是"joelli"
- strutil.contain ${ strutil.contain ("hello,"el")},输出是true
- strutil.toUpperCase ${ strutil.toUpperCase ("hello")},输出是HELLO
- strutil.toLowerCase ${ strutil.toLowerCase ("hello")},输出是hello
- strutil.replace ${ strutil.replace ("hello","lo","loooo")},输出是helloooo
- strutil.format ${ strutil.format ("hello,{0}, my age is {1}","joeli",15)},输出是hello,joeli, my age is 15. 具体请参考http://docs.oracle.com/javase/6/docs/api/java/text/MessageFormat.html
- strutil.trim 去掉字符串的尾部空格
- strutil.formatDate var a = strutil.formatDate(user.bir,'yyyy-MM-dd')};
- strutil.index var index = strutil.index("abc","a");返回 索引0
- strutil.lastIndex var index = strutil.lastIndex("aba","a");返回索引2
更多参见:http://ibeetl.com/guide/#/beetl/other?id=%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E5%85%B3%E6%96%B9%E6%B3%95
数组相关
- array.range 返回数组或者Collection一部分,接受三个参数,第一个是数组或者Collection子类,第二,三个参数分别是起始位置
- array.remove 删除某个数组或者Collection的一个元素,并返回该数组或者Collection.第一个是数组或者Collection子类,第二个参数是元素
- array.add 向数组或者Collection添加一个元素,并返回该数组或者Collection。第一个是数组或者Collection子类,第二个参数是元素
- array.contain 判断数组或者元素是否包含元素,如果包含,返回true。否则false。第一个是数组或者Collection子类,第二个参数是元素
- array.toArray 转化成数组,如array.toArray(1,2,"a");
- array.collection2Array 将java集合转化为数组 array.collection2Array([1,2,''])
更多参见:http://ibeetl.com/guide/#/beetl/other?id=%E6%95%B0%E7%BB%84%E7%9B%B8%E5%85%B3%E6%96%B9%E6%B3%95
另外在线体验页面:http://ibeetl.com/beetlonline/
本文暂时没有评论,来添加一个吧(●'◡'●)