Files
struts2-demo/web/demo/model/index.jsp

55 lines
2.4 KiB
Plaintext

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模型绑定指南</title>
<style>
body { margin: 0; padding: 24px; font-family: "Aptos", "Segoe UI", sans-serif; background: linear-gradient(135deg, #7c3aed, #a855f7); }
.shell { max-width: 980px; margin: 0 auto; background: rgba(255,255,255,0.96); border-radius: 28px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,0.18); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: #7c3aed; font-weight: 800; }
h1, h2 { margin: 10px 0 12px; }
p, li { color: #5e5570; line-height: 1.9; }
pre { background: #101827; color: #d9e7ff; padding: 18px; border-radius: 18px; overflow-x: auto; }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn { display: inline-flex; padding: 10px 14px; border-radius: 999px; text-decoration: none; font-weight: 700; background: #f0e9ff; color: #7c3aed; }
</style>
</head>
<body>
<div class="shell">
<div class="eyebrow">指南</div>
<h1>属性绑定与 ModelDriven 绑定怎么理解</h1>
<p>这页用来解释 Struts2 如何把请求参数装配进 Action。建议配合用户资料表单和字段校验实验一起看。</p>
<h2>属性驱动绑定</h2>
<ul>
<li>直接在 Action 上定义简单字段。</li>
<li>为表单字段提供对应的 setter / getter。</li>
<li>适合短流程 Demo 和小型表单。</li>
</ul>
<h2>ModelDriven 绑定</h2>
<ul>
<li>通过 <code>getModel()</code> 返回一个独立模型对象。</li>
<li>把请求数据和 Action 编排逻辑拆开。</li>
<li>更适合复杂表单和嵌套对象。</li>
</ul>
<pre>public class UserAction extends ActionSupport implements ModelDriven&lt;User&gt; {
private final User user = new User();
@Override
public User getModel() {
return user;
}
}</pre>
<div class="links">
<a class="btn" href="../../userFormPage.action">打开用户表单实验</a>
<a class="btn" href="../../index.action">返回门户</a>
</div>
</div>
</body>
</html>