DWR增删改查Word格式文档下载.docx
《DWR增删改查Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《DWR增删改查Word格式文档下载.docx(10页珍藏版)》请在冰豆网上搜索。
}else{
添加失败!
}
/script>
<
/head>
body>
<
tableid="
mytable"
border="
1"
<
tr>
<
td>
用户名称
/td>
<
inputtype="
text"
name="
/>
/tr>
用户密码
button"
value="
添加"
onclick="
addAccount();
/table>
/body>
Index页面
window.onload=function(){
account.queryAll(callBackQueryAll);
functioncallBackQueryAll(data){
if(data!
=null){
for(vari=0;
i<
data.length;
i++){
varrow=document.getElementById("
).insertRow(
document.getElementById("
).rows.length);
row.insertCell(0).innerHTML=data[i].accountId;
row.insertCell
(1).innerHTML=data[i].accountName;
row.insertCell
(2).innerHTML=data[i].accountPwd;
row.insertCell(3).innerHTML="
ahref='
javascript:
deleteAccount("
+data[i].accountId
+"
'
删除<
/a>
&
nbsp;
update.jsp?
accountId="
+data[i].accountId+"
修改<
}
NO!
functiondeleteAccount(id){
account.deleteAccount(id,callBackDelete);
functioncallBackDelete(data){
删除成功!
window.location.href=window.location.href;
删除失败!
tralign="
center"
用户ID
操作
div>
ahref="
add.jsp"
添加<
/div>
Update页面
var$=document.getElementById;
functionqueryById(id){
account.queryById(id,callBackQueryById);
functioncallBackQueryById(data){
$("
accountId"
).value=data.accountId;
).value=data.accountName;
).value=data.accountPwd;
functionupdateAccount(){
varaccountId=$("
account.updateAccount(accountId,accountName,accountPwd,
callBackDelete);
更新成功!
更新失败!
bodyonload="
queryById(${param.accountId});
hidden"
${account.accountId}"
value="
${account.accountName}"
${account.accountPwd}"
更新"
updateAccount();
底层方法调用
publicList<
Account>
queryAll(){
List<
list=accountDAO.findAll();
returnlist.size()>
0?
list:
null;
publicAccountqueryById(intid){
Accountaccount=accountDAO.findById(id);
returnaccount!
=null?
account:
publicbooleanupdate(Accountaccount){
booleanflag=false;
try{
accountDAO.attachDirty(account);
flag=true;
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
returnflag;
publicbooleanupdateAccountBO(intaccountId,StringuserName,StringuserPwd){
Accountaccount=newAccount();
account.setAccountId(accountId);
account.setAccountName(userName);
account.setAccountPwd(userPwd);
returnaccountDAOImpl.update(account);
publicbooleandelete(intid){
Accountaccount=this.queryById(id);
accountDAO.delete(account);
publicbooleanadd(StringuserName,StringuserPwd){
Accountaccount=newAccount();
account.setAccountName(userName);
account.setAccountPwd(userPwd);
accountDAO.save(account);
Web.xml
!
--以classpath方式加载配置文件-->
context-param>
param-name>
contextConfigLocation<
/param-name>
param-value>
/WEB-INF/applicationContext.xml
/param-value>
/context-param>
--以listener方式加载-->
listener>
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
/listener>
--dwr-->
servlet>
servlet-name>
dwr-invoker<
/servlet-name>
servlet-class>
org.directwebremoting.servlet.DwrServlet<
/servlet-class>
init-param>
debug<
true<
/init-param>
/servlet>
servlet-mapping>
url-pattern>
/dwr/*<
/url-pattern>
/servlet-mapping>
welcome-file-list>
welcome-file>
index.jsp<
/welcome-file>
/welcome-file-list>
DWR.xml
dwr>
allow>
createcreator="
spring"
javascript="
account"
paramname="
beanName"
accountBO"
/param>
/create>
convertmatch="
com.scce.dwr.account.pojo.*"
converter="
bean"
/convert>
/allow>
/dwr>
Application.xml
beanid="
sessionFactory"
class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean"
propertyname="
configLocation"
classpath:
hibernate.cfg.xml"
/property>
/bean>
AccountDAO"
class="
com.scce.dwr.account.pojo.AccountDAO"
refbean="
accountDAOImpl"
com.scce.dwr.account.pojo.AccountDAOImpl"
accountDAO"
com.scce.dwr.account.pojo.AccountBO"