feat: expand struts demo lab

This commit is contained in:
Codex
2026-03-18 18:12:20 +08:00
parent 1f60832445
commit fba7b0497f
25 changed files with 1847 additions and 1447 deletions

View File

@@ -2,33 +2,50 @@ package com.demo.action;
import com.opensymphony.xwork2.ActionSupport;
/**
* Hello World 示例 Action
* 展示 Struts2 最基础的 Action 写法
*
* ActionSupport 提供了:
* - validate() 方法用于表单验证
* - getText() 方法用于国际化
* - addActionError()/addFieldError() 用于错误消息
*/
public class HelloAction extends ActionSupport {
private String name;
private String message;
private String tip;
private String nextStep;
private String requestSample;
@Override
public String execute() throws Exception {
// 业务逻辑
public String execute() {
if (name == null || name.trim().isEmpty()) {
name = "World";
} else {
name = name.trim();
}
message = "Hello, " + name + "! 欢迎学习 Struts2!";
message = "Hello, " + name + "! Welcome to the Struts2 demo lab.";
tip = "Struts2 injected the request parameter into the action property before execute() ran.";
nextStep = "Try the login flow or open the demo catalog to compare different action patterns.";
requestSample = "/hello?name=Platform%20Team";
return SUCCESS;
}
// Getter/Setter (Struts2 需要这些来获取/设置参数)
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public String getTip() {
return tip;
}
public String getNextStep() {
return nextStep;
}
public String getRequestSample() {
return requestSample;
}
}