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

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

先来看表现层:

新增或修改用户页面:


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


用户列表页面:

SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02<%SpringSide示例之HelloWorld_spring_03@ page contentType="text/html;charset=UTF-8" %>
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
<%SpringSide示例之HelloWorld_spring_03@ include file="/commons/taglibs.jsp" %>
SpringSide示例之HelloWorld_struts_07
<html>
SpringSide示例之HelloWorld_struts_07
<head>
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02    
<%SpringSide示例之HelloWorld_spring_03@ include file="/commons/meta.jsp" %>
SpringSide示例之HelloWorld_struts_07    
<link href="${ctx}/widgets/extremecomponents/extremecomponents.css" type="text/css" rel="stylesheet">
SpringSide示例之HelloWorld_struts_07    
<title>User Manage</title>
SpringSide示例之HelloWorld_struts_07
</head>
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07
<body>
SpringSide示例之HelloWorld_struts_07
<div id="page">
SpringSide示例之HelloWorld_struts_07    
<div id="header">
SpringSide示例之HelloWorld_struts_07        
<h1>Helloworld Sample</h1>
SpringSide示例之HelloWorld_struts_07    
</div>
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07    
<div id="content">
SpringSide示例之HelloWorld_struts_07        
<h1>User List</h1>
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02        
<%SpringSide示例之HelloWorld_spring_03@ include file="/commons/messages.jsp" %>
SpringSide示例之HelloWorld_struts_07        
<ec:table items="users" var="user"
SpringSide示例之HelloWorld_struts_07                  action
="${ctx}/user.do">
SpringSide示例之HelloWorld_struts_07            
<ec:exportXls fileName="UserList.xls" tooltip="Export Excel"/>
SpringSide示例之HelloWorld_struts_07            
<ec:row>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="rowcount" cell="rowCount" sortable="false" title="No." width="60"/>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="id" title="ID" width="60"/>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="name" title="Name" width="120"/>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="email" title="Email" width="120"/>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="descn" title="Description" viewsDenied="html"/>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="null" title="Edit" width="40" sortable="false" viewsAllowed="html">
SpringSide示例之HelloWorld_struts_07                    
<href="user.do?method=edit&id=${user.id}">Edit</a>
SpringSide示例之HelloWorld_struts_07                
</ec:column>
SpringSide示例之HelloWorld_struts_07                
<ec:column property="null" title="Remove" width="40" sortable="false" viewsAllowed="html">
SpringSide示例之HelloWorld_struts_07                    
<href="user.do?method=delete&id=${user.id}">Delete</a>
SpringSide示例之HelloWorld_struts_07                
</ec:column>
SpringSide示例之HelloWorld_struts_07            
</ec:row>
SpringSide示例之HelloWorld_struts_07        
</ec:table>
SpringSide示例之HelloWorld_struts_07    
</div>
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07    
<div>
SpringSide示例之HelloWorld_struts_07        
<button id="addbtn" onclick="location.href='user.do?method=create'">Add</button>
SpringSide示例之HelloWorld_struts_07    
</div>
SpringSide示例之HelloWorld_struts_07
</div>
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
<%SpringSide示例之HelloWorld_spring_03@ include file="/commons/footer.jsp" %>
SpringSide示例之HelloWorld_struts_07
</body>
SpringSide示例之HelloWorld_struts_07
</html>
SpringSide示例之HelloWorld_struts_07

对应的控制器类UserAction.java:


SpringSide示例之HelloWorld_struts_07package org.springside.helloworld.web;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07
import org.springside.core.web.StrutsEntityAction;
SpringSide示例之HelloWorld_struts_07
import org.springside.helloworld.model.User;
SpringSide示例之HelloWorld_struts_07
import org.springside.helloworld.service.UserManager;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
/** *//**
SpringSide示例之HelloWorld_spring_128 * 用户管理Controller.
SpringSide示例之HelloWorld_spring_128 * <p/>
SpringSide示例之HelloWorld_spring_128 * 继承于StrutsEntityAction,不需编码就拥有默认的对User对象的CRUD响应函数. 如果想了解不继承于EntityAction,自行编写CRUD的写法, 参考{
@link UserActionNativeVersion}.
SpringSide示例之HelloWorld_spring_128 *
SpringSide示例之HelloWorld_spring_128 * 
@author calvin
SpringSide示例之HelloWorld_spring_128 * 
@see org.springside.core.web.StrutsEntityAction
SpringSide示例之HelloWorld_spring_128 * 
@see org.springside.core.web.StrutsAction
SpringSide示例之HelloWorld_spring_128 * 
@see UserActionNativeVersion
SpringSide示例之HelloWorld_ide_136 
*/

SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
public class UserAction extends StrutsEntityAction<User, UserManager> SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_128    @SuppressWarnings(
"unused")
SpringSide示例之HelloWorld_spring_128    
private UserManager userManager;
SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public void setUserManager(UserManager userManager) SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
this.userManager = userManager;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_ide_136}

SpringSide示例之HelloWorld_struts_07


然后是业务逻辑层,

SpringSide示例之HelloWorld_struts_07package org.springside.helloworld.service;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07
import org.springside.core.dao.HibernateEntityDao;
SpringSide示例之HelloWorld_struts_07
import org.springside.helloworld.model.User;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
/** *//**
SpringSide示例之HelloWorld_spring_128 * 用户管理业务类.
SpringSide示例之HelloWorld_spring_128 * <p/>
SpringSide示例之HelloWorld_spring_128 * 继承于HibernateEntityDao,不需任何代码即拥有默认的对User对象的CRUD函数. 如果想了解不继承于EntityDao,自行编写CRUD的写法, 参考{
@link UserManagerNativeVersion}.
SpringSide示例之HelloWorld_spring_128 *
SpringSide示例之HelloWorld_spring_128 * 
@author calvin
SpringSide示例之HelloWorld_spring_128 * 
@see HibernateEntityDao
SpringSide示例之HelloWorld_spring_128 * 
@see org.springside.core.dao.HibernateGenericDao
SpringSide示例之HelloWorld_spring_128 * 
@see UserManagerNativeVersion
SpringSide示例之HelloWorld_ide_136 
*/

SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
public class UserManager extends HibernateEntityDao<User> SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128    
// SpringSide示例之HelloWorld_spring_03.CRUD以外的其它商业方法
SpringSide示例之HelloWorld_ide_136
}

SpringSide示例之HelloWorld_struts_07

然后是模型层


SpringSide示例之HelloWorld_struts_07package org.springside.helloworld.model;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07
import javax.persistence.Entity;
SpringSide示例之HelloWorld_struts_07
import javax.persistence.GeneratedValue;
SpringSide示例之HelloWorld_struts_07
import javax.persistence.GenerationType;
SpringSide示例之HelloWorld_struts_07
import javax.persistence.Id;
SpringSide示例之HelloWorld_struts_07
import javax.persistence.Table;
SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
/** *//**
SpringSide示例之HelloWorld_spring_128 * 用户.带jpa annotation简版配置.
SpringSide示例之HelloWorld_spring_128 *
SpringSide示例之HelloWorld_spring_128 * 
@author calvin
SpringSide示例之HelloWorld_spring_128 * 
@author schweigen
SpringSide示例之HelloWorld_ide_136 
*/

SpringSide示例之HelloWorld_struts_07 
//同USERS表映射
SpringSide示例之HelloWorld_struts_07
@Entity
SpringSide示例之HelloWorld_struts_07@Table(name 
= "USERS")
SpringSide示例之HelloWorld_struts_07
public class User 
SpringSide示例之HelloWorld_springSpringSide示例之HelloWorld_ide_02
SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128    
private Integer id;//用户id 
SpringSide示例之HelloWorld_spring_128

SpringSide示例之HelloWorld_spring_128    
private String name;//用户名
SpringSide示例之HelloWorld_spring_128

SpringSide示例之HelloWorld_spring_128    
private String email;//e-mail
SpringSide示例之HelloWorld_spring_128

SpringSide示例之HelloWorld_spring_128    
private String descn;//自我介绍
SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_128    
//主键自动生成,其他,其余属性全部与数据库中的列默认映射。
SpringSide示例之HelloWorld_spring_128
    @Id
SpringSide示例之HelloWorld_spring_128    @GeneratedValue(strategy 
= GenerationType.AUTO)
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public Integer getId() SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
return id;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public void setId(Integer id) SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
this.id = id;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public String getName() SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
return name;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public void setName(String name) SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
this.name = name;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public String getEmail() SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
return email;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public void setEmail(String email) SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
this.email = email;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public String getDescn() SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
return descn;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_spring_128
SpringSide示例之HelloWorld_spring_144SpringSide示例之HelloWorld_html_145    
public void setDescn(String descn) SpringSide示例之HelloWorld_spring_03{
SpringSide示例之HelloWorld_spring_128        
this.descn = descn;
SpringSide示例之HelloWorld_ide_148    }

SpringSide示例之HelloWorld_ide_136}

SpringSide示例之HelloWorld_struts_07
SpringSide示例之HelloWorld_struts_07


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