我想显示一个编辑表单,用户可以在其中更改旧数据。 所以我想用数据库中的值来预先形成表单?
请告诉我如何在struts2中执行此操作?
答案 0 :(得分:2)
此拦截器对实现的操作调用prepare() 制备。这种拦截器对于任何情况都非常有用 你需要确保在实际执行方法之前运行一些逻辑 运行。
示例: Struts2 UI Tags similar to pre-population logic.
package com.examples;
public class RegistrationAction extends ActionSupport implements Preparable {
@Override
public void prepare() throws Exception {
// get the data that you want to pre-populate
}
public String execute() {
// you action logic
return SUCCESS;
}
}
<!-- Calls the params interceptor twice, allowing you to pre-load data for the second time parameters are set -->
<!-- don't forgot to add prepare interceptor to interceptor stack -->
<action name="someAction" class="com.examples.RegistrationAction">
<interceptor-ref name="params"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="basicStack"/>
<result name="success">good_result.ftl</result>
</action>