思路:根據user的id去刪除數據,直接從UserList頁面實現刪除。html
修改UserList.java,與UserList.tml文件。代碼以下:java
UserList.javasql
/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 編寫:飛風
* 時間:2012-02-29
*/
package com.tapestry.app.pages.crud;
import java.util.List;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import com.tapestry.app.entities.User;
import com.tapestry.app.services.StartDAO;
public class UserList {
//打開user讀寫
@Property
private User user;
//打開user陣列的讀寫
@Property
private List<User> users;
//導入操做數據庫的服務
@Inject
private StartDAO dao;
//當前頁面接收user的id值
@PageActivationContext
private Long id;
//頁面加載時設置渲染
void setupRender(){
//查詢User數據表
StringBuffer sql = new StringBuffer();
sql.append("from User");
users = dao.findWithQuery(sql.toString());
}
//單擊eventlink執行刪除操做
Object onDelete(Long id){
dao.deleteByID(User.class, id);
return this;
}
}
UserList.tml數據庫
<html t:type="layout" title="tapestryStart Index" t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<style>
.table{border-collapse: collapse; }
.table td,table th{border:1px solid #999; padding:5px;"}
</style>
<t:pagelink page="crud/UserCreate">添加用戶</t:pagelink><br/><br/>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
<tr>
<th scope="col">id</th>
<th scope="col">用戶名</th>
<th scope="col">年齡</th>
<th scope="col">時間</th>
<th scope="col">操做</th>
</tr>
<tr t:type="loop" t:source="users" t:value="user">
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.age}</td>
<td>${user.time}</td>
<td><t:pagelink page="crud/UserUpdate" t:context="${user.id}">修改</t:pagelink> | <t:eventlink t:event="delete" t:context="${user.id}">刪除</t:eventlink></td>
</tr>
</table>
</html>
查看http://localhost/crud/userlist刪除已經作好了apache