日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringSide示例之HelloWorld

發布時間:2023/11/29 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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新加入的泛型技術的運用更是如虎添翼。那么對于配置文件部分,我個人感覺比以前好像更加復雜了呢,也許是還不習慣吧。。。

總結

以上是生活随笔為你收集整理的SpringSide示例之HelloWorld的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。