ホームページ  >  記事  >  バックエンド開発  >  速度の 7 番目の応用例 - テンプレートでの値の割り当て

速度の 7 番目の応用例 - テンプレートでの値の割り当て

黄舟
黄舟オリジナル
2017-01-17 11:00:271477ブラウズ

速度 7 番目のアプリケーション例----テンプレートでの代入

//2 Create a Context object

VelocityContext context = newVelocityContext();

//3 Add you data object to this context

context.put("name", "老毕");

//4 Choose a template

Template template =Velocity.getTemplate("template7.vm");

//5 Merge the template and you data toproduce the output

StringWriter sw = new StringWriter();

template.merge(context, sw);

sw.flush();

System.out.println(sw.toString());

template

配列の代入

#set($ints=["第一个","第二个","第三个"])

#foreach($entryin $ints)


$entry

#end



===

#set($ints=[1..10])

#foreach($int in $ints)


$int

#end



===



${name}

===============

#set($name="军旗")

$name

===

#set($condition=true)

#set($condition=false)

#if($condition)

確立

#else

未確立

#end

====

上 これは速度の 7 番目の応用例 - テンプレートに値を割り当てる さらに関連する内容については、PHP 中国語 Web サイト (www.php.cn) に注目してください。


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。