SpringSide示例之HelloWorld

简介:
SpringSide是个什么东西呢?这么说吧,就是“采众家之长”的一个一站式框架,它吸取了开源界许多优秀组件的精华部分,非常简约的一个东西,具体就不多介绍了,自己可以参考官方文档。

下面来看看运用这个框架实现一个简单的用户管理究竟有多么容易。

先来看表现层:

新增或修改用户页面:


复制代码
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
    <%@ include file="/commons/meta.jsp" %>
    <title>User Manage</title>
</head>

<body>
<div id="page">
    <div id="header">
        <h1>Helloworld Sample</h1>
    </div>
    <%@ include file="/commons/messages.jsp" %>
    <div id="content">
        <h1>User Infomation Manage</h1>
        <html:form action="/user.do" focus="name" styleClass="form" onsubmit="return validateUserForm(this)">
            <input type="hidden" name="method" value="save"/>
            <html:hidden property="id"/>
            <table>
                <tr>
                    <td><label>Name</label></td>
                    <td>
                        <html:text property="name" styleClass="text"/>
                        <span class="req">*</span>
                        <span class="fieldError"><html:errors property="name"/></span>
                    </td>
                </tr>
                <tr>
                    <td><label>EMail</label></td>
                    <td>
                        <html:text property="email" styleClass="text"/>
                    </td>
                </tr>
                <tr>
                    <td><label>Remark</label></td>
                    <td>
                        <html:textarea property="descn" rows="10" cols="40"/>
                    </td>
                </tr>
            </table>
            <div>
                <html:submit property="saveBtn" styleClass="button">Save</html:submit>
                <html:cancel styleClass="button">Cancel</html:cancel>
            </div>
        </html:form>
    </div>
</div>
<html:javascript formName="userForm" staticJavascript="false" dynamicJavascript="true" cdata="false"/>
<script type="text/javascript" src="${ctx}/scripts/validator.jsp"></script>
<%@ include file="/commons/footer.jsp" %>
</body>
</html>

复制代码


用户列表页面:

复制代码
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
    <%@ include file="/commons/meta.jsp" %>
    <link href="${ctx}/widgets/extremecomponents/extremecomponents.css" type="text/css" rel="stylesheet">
    <title>User Manage</title>
</head>

<body>
<div id="page">
    <div id="header">
        <h1>Helloworld Sample</h1>
    </div>

    <div id="content">
        <h1>User List</h1>
        <%@ include file="/commons/messages.jsp" %>
        <ec:table items="users" var="user"
                  action="${ctx}/user.do">
            <ec:exportXls fileName="UserList.xls" tooltip="Export Excel"/>
            <ec:row>
                <ec:column property="rowcount" cell="rowCount" sortable="false" title="No." width="60"/>
                <ec:column property="id" title="ID" width="60"/>
                <ec:column property="name" title="Name" width="120"/>
                <ec:column property="email" title="Email" width="120"/>
                <ec:column property="descn" title="Description" viewsDenied="html"/>
                <ec:column property="null" title="Edit" width="40" sortable="false" viewsAllowed="html">
                    <a href="user.do?method=edit&id=${user.id}">Edit</a>
                </ec:column>
                <ec:column property="null" title="Remove" width="40" sortable="false" viewsAllowed="html">
                    <a href="user.do?method=delete&id=${user.id}">Delete</a>
                </ec:column>
            </ec:row>
        </ec:table>
    </div>

    <div>
        <button id="addbtn" onclick="location.href='user.do?method=create'">Add</button>
    </div>
</div>
<%@ include file="/commons/footer.jsp" %>
</body>
</html>

复制代码
对应的控制器类UserAction.java:


复制代码
package org.springside.helloworld.web;

import org.springside.core.web.StrutsEntityAction;
import org.springside.helloworld.model.User;
import org.springside.helloworld.service.UserManager;

/**
 * 用户管理Controller.
 * <p/>
 * 继承于StrutsEntityAction,不需编码就拥有默认的对User对象的CRUD响应函数. 如果想了解不继承于EntityAction,自行编写CRUD的写法, 参考{@link UserActionNativeVersion}.
 *
 * @author calvin
 * @see org.springside.core.web.StrutsEntityAction
 * @see org.springside.core.web.StrutsAction
 * @see UserActionNativeVersion
 */
public class UserAction extends StrutsEntityAction<User, UserManager> {

    @SuppressWarnings("unused")
    private UserManager userManager;

    public void setUserManager(UserManager userManager) {
        this.userManager = userManager;
    }
}

复制代码


然后是业务逻辑层,

复制代码
package org.springside.helloworld.service;

import org.springside.core.dao.HibernateEntityDao;
import org.springside.helloworld.model.User;

/**
 * 用户管理业务类.
 * <p/>
 * 继承于HibernateEntityDao,不需任何代码即拥有默认的对User对象的CRUD函数. 如果想了解不继承于EntityDao,自行编写CRUD的写法, 参考{@link UserManagerNativeVersion}.
 *
 * @author calvin
 * @see HibernateEntityDao
 * @see org.springside.core.dao.HibernateGenericDao
 * @see UserManagerNativeVersion
 */
public class UserManager extends HibernateEntityDao<User> {
    // .CRUD以外的其它商业方法
}

复制代码
然后是模型层


复制代码
package org.springside.helloworld.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 用户.带jpa annotation简版配置.
 *
 * @author calvin
 * @author schweigen
 */
 //同USERS表映射
@Entity
@Table(name = "USERS")
public class User 
{
    private Integer id;//用户id 

    private String name;//用户名

    private String email;//e-mail

    private String descn;//自我介绍

    //主键自动生成,其他,其余属性全部与数据库中的列默认映射。
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDescn() {
        return descn;
    }

    public void setDescn(String descn) {
        this.descn = descn;
    }
}


复制代码


那么代码部分就这些了,可以看到不需要我们自己去写重复的CRUD代码,仅仅从一些特定的基类继承下来就可以了,而Jdk新加入的泛型技术的运用更是如虎添翼。那么对于配置文件部分,我个人感觉比以前好像更加复杂了呢,也许是还不习惯吧。。。




本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/07/03/1234894.html,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
前端开发 C++
DeepSeek & Mermaid:如何将文本直接转化为精美图表? -优雅草卓伊凡
DeepSeek & Mermaid:如何将文本直接转化为精美图表? -优雅草卓伊凡
509 4
DeepSeek & Mermaid:如何将文本直接转化为精美图表? -优雅草卓伊凡
|
11月前
|
安全 数据中心
|
9月前
|
存储 算法 区块链
区块链:版权保护的新利器
区块链:版权保护的新利器
587 21
|
JSON 数据可视化 数据挖掘
Polars函数合集大全:大数据分析的新利器
Polars函数合集大全:大数据分析的新利器
681 1
|
存储 Ubuntu 关系型数据库
PolarDB-X部署测评
7月更文挑战第1天
|
12月前
|
Java 应用服务中间件 Apache
浅谈Tomcat和其他WEB容器的区别
Tomcat是一款轻量级的免费开源Web应用服务器,常用于中小型系统及并发访问量适中的场景,尤其适合开发和调试JSP程序。它不仅能处理HTML页面,还充当Servlet和JSP容器。相比之下,物理服务器是指具备处理器、硬盘等硬件设施的服务器,如云服务器,其设计目标是在处理能力、稳定性和安全性等方面提供高标准服务。简言之,Tomcat专注于运行Java应用,而物理服务器则提供基础计算资源。
|
XML 数据格式
mybatis-plus随机查询工具类
mybatis-plus随机查询工具类
338 0
|
机器学习/深度学习 Python
【Python】已解决:ModuleNotFoundError: No module named ‘paddle’
【Python】已解决:ModuleNotFoundError: No module named ‘paddle’
1593 1
|
定位技术
哨兵2号Sentinel-2分幅条带介绍与MGRS网格矢量文件获取
哨兵2号Sentinel-2分幅条带介绍与MGRS网格矢量文件获取
388 1
|
存储 NoSQL 关系型数据库
DTS是什么的缩写
【5月更文挑战第1天】DTS是什么的缩写
1478 1