fix(structs): limit user form validation to add/update flows
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
* - 动态方法调用
|
||||
*/
|
||||
public class UserFormAction extends ActionSupport {
|
||||
private String actionName;
|
||||
|
||||
private static List<User> users = new ArrayList<>();
|
||||
private static Long idCounter = 1L;
|
||||
@@ -70,6 +71,9 @@ public class UserFormAction extends ActionSupport {
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
if (!("user_add".equals(actionName) || "user_update".equals(actionName))) {
|
||||
return;
|
||||
}
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
@@ -93,6 +97,8 @@ public class UserFormAction extends ActionSupport {
|
||||
|
||||
public List<User> getUserList() { return userList; }
|
||||
public void setUserList(List<User> userList) { this.userList = userList; }
|
||||
public String getActionName() { return actionName; }
|
||||
public void setActionName(String actionName) { this.actionName = actionName; }
|
||||
|
||||
// 内部类 - 用户实体
|
||||
public static class User {
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
</action>
|
||||
|
||||
<action name="user_add" class="com.example.struts2.UserFormAction" method="add">
|
||||
<param name="actionName">user_add</param>
|
||||
<result type="redirectAction">user</result>
|
||||
<result name="input">/user-form.jsp</result>
|
||||
</action>
|
||||
@@ -94,6 +95,7 @@
|
||||
</action>
|
||||
|
||||
<action name="user_update" class="com.example.struts2.UserFormAction" method="update">
|
||||
<param name="actionName">user_update</param>
|
||||
<result type="redirectAction">user</result>
|
||||
<result name="input">/user-form.jsp</result>
|
||||
</action>
|
||||
|
||||
Reference in New Issue
Block a user