步驟1.
創建一個SOY文件(格式和語法講過,在此省略),文件名是magic-action.soy,模板全名是:Magical.templates.main
步驟2.
在 <web resource>配置中聲明SOY 文件。
<web-resource key="action-templates">
<resource type="soy" name="does-not-matter" location="somewhere/magic-action.soy"/>
</web-resource>
magic-action.soy"/>
</web-resource>
步驟3.
配置添加 action,讓action返回的視圖指向 SOY 文件。
<webwork1 key="some-magic" class="java.lang.Object">
<actions>
<action name="com.example.MagicAction" alias="Magic">
<view type="soy" name="input">:action-templates/Magical.templates.main</view> <!-:action-templates與web resource的key對應->
</action>
</actions>
</webwork1>
:action-templates/Magical.templates.main</view> <!-:action-templates與web resource的key對應->
</action>
</actions>
</webwork1>
注意:
3.1<view>標籤中的文本內容 :action-templates,這是簡寫的方式,標準寫法是 plugin key : web-resource key.
3.2爲了能把數據傳入模板中,需要在action相應的方法上添加註釋:@ActionViewData,該方法必須沒有參數並有返回值。