B101是一个根据查询条件查询结果的业务逻辑类,它先把从Request取出的查询参数,封装成一个BorrowGood对象。然后传入这个BorrowGood对象调用getGoodByParams服务,返回数据库中相符合的所有数据集合。之后,将数据重新截成前台分页显示所需要的格式。最后将符合前台分页格式的数据封装成JSON数据发送到前台。
下图是根据B101Controller得到的前台数据界面截图
图5.1 B101Controller页面截图
2. B102Controller(部分代码) User user=new User();
user.setStuId(request.getParameter(\)); BorrowGood borrowGood=new BorrowGood(); if(request.getParameter(\)!=null)
borrowGood.setId(Integer.parseInt(request.getParameter(\))); borrowGood.setReturnStatus(\);
if(borrowGoodManageService.updateGoodById(borrowGood, user)){
response.getWriter().println(1);
}else{
36
}
response.getWriter().println(0);
B102是物资归还的业务逻辑类,它从cookie中获得当前正在进行此操作的用户学号,通过把Request里的当前操作的物资记录Id参数取出来,将其归还状态设置为YES。然后执行updateGoodById服务,若归还成功,则返回给前台1这个数据,否则返回0。
3. B103Controller(部分代码) //得到cookie
Cookie[] cookies=request.getCookies(); Cookie currentusername=null; for(Cookie cookie:cookies){
if(cookie.getName().equals(\)) }
user.setStuId(currentusername.getValue()); user=userManageService.doUserByStuId(user); borrowGood.setBorrowCheckInUser(user.getName());
borrowGood.setBorrowDate(request.getParameter(\)); borrowGood.setBorrowOrganization(request.getParameter(\ization\));
currentusername=cookie;
String borrowStatus=request.getParameter(\); if(borrowStatus.equals(\借用\)){
borrowStatus=\;
}else{
borrowStatus=\;
}
borrowGood.setBorrowStatus(request.getParameter(\));
37
borrowGood.setBorrowStu(request.getParameter(\));
borrowGood.setBorrowStuPhone(request.getParameter(\));
borrowGood.setDetail(request.getParameter(\)); borrowGood.setGoodName(request.getParameter(\));
borrowGood.setGoodNum(Integer.parseInt(request.getParameter(%um\)));
borrowGood.setReturnDate(request.getParameter(\)); borrowGood.setReturnStatus(\);
if(borrowGoodManageService.addBorrowGood(borrowGood)){
response.getWriter().println(1);
}else{
response.getWriter().println(0);}
B103是物资借用的业务逻辑类,它从cookie中获得当前正在进行此操作的用户id,从而根据id在数据库中找出此Id的用户信息。然后将用户的必要信息,以及从Request的参数中得到的数据封装成BorrwGood类。然后调用addBorrowGood服务,传入User与BorrowGood这两个实体,完成添加物资的操作。若此物资的余量充足,则添加物资成功,返回给前台的信息是1,否则返回给前台的信息是0。
下图是根据B103Controller逻辑得到的物资借用截图。
38
图5.2 B103Controller页面截图
4.B104 Controller(部分代码)
BorrowGood borrowGood=new BorrowGood(); User user=new User();
user.setStuId(request.getParameter(\));
39
user=userManageService.doUserByStuId(user); if(request.getParameter(\)!=null)
borrowGood.setId(Integer.parseInt(request.getParameter(\))); borrowGood.setBorrowDate(request.getParameter(\)); borrowGood.setBorrowOrganization(request.getParameter(\ization\));
borrowGood.setBorrowStu(request.getParameter(\)); borrowGood.setBorrowStuPhone(request.getParameter(\));
borrowGood.setDetail(request.getParameter(\)); borrowGood.setGoodNum(Integer.parseInt(request.getParameter(%um\)))
borrowGood.setReturnDate(request.getParameter(\)); if(borrowGoodManageService.updateGoodById(borrowGood, user)){
response.getWriter().println(1);
}else{ }
B104是编辑借用信息的业务逻辑类。它从cookie中获得当前正在进行此操作的用户id,从而根据id在数据库中找出此Id的用户信息。然后将用户的必要信息,以及从Request的参数中得到的数据封装成BorrwGood类。。然后调用updateGoodById服务,传入User与BorrowGood这两个实体,完成编辑物资的操作。若编辑成功,返回给前台的信息是1,否则返回给前台的信息是0。
下图是根据B104Controller得到的用户界面截图。
图5.3 B104Controller界面截图
response.getWriter().println(0);
5.B105Controller(部分代码)
borrowGood.setGoodName(request.getParameter(\));
40