步骤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,该方法必须没有参数并有返回值。