层的存款方法中编写代码。在DAO层使用SQL语句编写存款进行数据处理。在Service层调用DAO层的存款的数据处理方法编写存款的业务逻辑方法。在Action层调用Service层的存款业务逻辑方法实现存款功能。如图1-3
1-3 存款界面
3、取款模块:
a)取款款的业务逻辑:首先从数据库中查找该用户的用户帐号如果不存在则无法进行取款,若该用户存在,将用户存款前的金额与存款金额相减得到
总金额,并存入数据库。
b)取款的操作描述:http://localhost:8088/springTeller/index.jsp为主页面,点击取款,输入用户的账户号,姓名,取款额度,达到取款需求。在业务逻辑层的取款方法中编写代码。
在DAO层使用SQL语句编写取款进行数据处理。在Service层调用DAO层的取款的数据处理方法编写存款的业务逻辑方法。在Action层调用Service层的取款业务逻辑方法实现取款功能。如图1-4
1-4 取款界面
21
? 操作要求:
在需要的功能模块中作出事物处理,保证与数据库数据一致。 根据以上要求编写代码。
参考答案:
基于ssh框架的银行取款项目(参考答案)
AccountServiceImpl.java //Service 层 :处理业务逻辑调用Dao层方法 (35分)
1. 开户 (15) public void openAccount(String accountno, String name, double amt)
throws AccountException { Account account=null; try {
account=accountDao.findAccountById(accountno); } catch (DataAccessException e1) {
//TODO Auto-generated catch block e1.printStackTrace();
}
if(account!=null){ throw new AccountException(\此用户已经存在!\}
Account a = new Account(); a.setAccountno(accountno); a.setName(name); a.setBalance(amt);
a.setOpendate(new Date()); a.setLastModified(new Date()); try {
accountDao.save(a);
} catch (DataAccessException e) { // TODO Auto-generated catch block }
e.printStackTrace();
}
2. 存款 (10)
22
public void deposit(String accountno, double amt) throws AccountException { try {
Account account=accountDao.findAccountById(accountno); if(account==null) { }
throw new AccountException(\用户不存在!!\
account.setBalance(account.getBalance()+amt); account.setLastModified(new Date());
}
}
} catch (DataAccessException e) { }
// TODO Auto-generated catch block e.printStackTrace();
3.取款 (10)
public void widthdraw(String accountno, double amt) throws AccountException { }
try {
Account account=accountDao.findAccountById(accountno); if(account==null) { }
throw new AccountException(\用户不存在!!\
account.setBalance(account.getBalance()-amt);
account.setLastModified(new Date()); } catch (DataAccessException e) { }
e.printStackTrace();
AccountAction.java //流程控制调用Service层方法 (30分)
4. 开户: (10分) public String openAccount(){
HttpServletRequest request = ServletActionContext.getRequest(); try { accountService.openAccount(accountno, name, balance);
request.setAttribute(\开户成功!\return \
} catch (AccountException e) { e.printStackTrace(); }
request.setAttribute(\开户失败!\return \
}
5. 存款: (10分)
23
public String deposit(){ HttpServletRequest request = ServletActionContext.getRequest(); Double amt=Double.parseDouble(request.getParameter(\
}
String accountno=request.getParameter(\try { accountService.deposit(accountno, amt); request.setAttribute(\存款成功!\ return SUCCESS; } catch (AccountException e) { // TODO Auto-generated catch block }
e.printStackTrace();
request.setAttribute(\存款失败!\return \
6. 取款: (10分) public String widthdraw(){ }
}
HttpServletRequest request = ServletActionContext.getRequest(); Double amt=Double.parseDouble(request.getParameter(\String accountno=request.getParameter(\try { accountService.widthdraw(accountno, amt);
request.setAttribute(\取款成功!\return SUCCESS;
} catch (AccountException e) { // TODO Auto-generated catch block request.setAttribute(\取款失败!\ e.printStackTrace();return \}
第二单元 代码调试
项目名称:网络书城(项目代码调试)
一、需求分析:
用户在注册页面,填写注册信息,确认有效注册成为新用户
用户在登录页面,填写用户名和密码,确认正确后进入系统 用户可以在登录之后,浏览图书分类列表页面
用户可以在选择分类编号后,浏览此分类详细图书列表
用户在图书浏览页面,点击”购买”按钮,把选定图书添加到购物车 用户可以在图书浏览页面点击”显示购物车”按钮查看购物车信息
24
用户可以在查看购物车页面点击”结帐”按钮,下订单 整个系统分为三个模块:
1)用户管理模块 负责用户注册登录
2)购物车管理模块 负责浏览图书添加到购物车里 3)订单管理模块 负责下订单结帐 二、功能描述:
1、 用户管理模块:
输入http://localhost:8088/estore_jsp/login.jsp进入用户登录页面,如果未注册,点击用户注册进行用户个人信息注册。若已经注册输入用户名,密码。点击提交按钮跳转到http://localhost:8088/estore_jsp/listBookStore.jsp图书列表页面。如图:2-1,2-2,2-3
图 2-1登陆界面
图2-2 注册界面
25