欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

开荒_TextbookOrderingSystem_管理员页面

程序员文章站 2022-03-16 16:30:03
...

Day2.3.4天

先看下管理员页面效果图
开荒_TextbookOrderingSystem_管理员页面
上代码。
管理员主界面jsp
manager.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all">
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body class="layui-layout-body ">
<div class="layui-layout  layui-layout-admin">
  <div class="layui-header ">
    <div class="layui-logo">教材征订系统</div>
    <!-- 头部区域(可配合layui已有的水平导航) -->
    <ul class="layui-nav  layui-layout-left"> 
      <li class="layui-nav-item"><a href="#">管理员</a></li> <!-- 显示为处理订单(处于审核中状态)的数量 -->
      <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/manage/ordersManageByStatus.jsp" target="option">待处理订单<span class="layui-badge">12</span></a></li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="${pageContext.request.contextPath}/${sessionScope.user.picture}" class="layui-nav-img">
          ${sessionScope.user.username}
        </a>
        <dl class="layui-nav-child">
          <dd><a href="${pageContext.request.contextPath}/jsp/userFaceEdit.jsp" target="option">基本资料</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
      <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/layuiadmin/loginout">退出</a></li>
    </ul>
  </div>
  <!-- 左侧导航区域(可配合layui已有的垂直导航) -->
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">  
       <li class="layui-nav-item"> 
         <a href="${pageContext.request.contextPath}/manage/userManageMain.jsp"  target="option">用户管理</a>
          <dl class="layui-nav-child">
               <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/usersManage.jsp" target="option">所有信息</a></dd>
               <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/usersManage.jsp" target="option">所有教师</a></dd>
               <dd data-name="edit"><a href="" target="option">所有学生</a></dd>
          </dl>
        </li>        
        <li class="layui-nav-item"> 
         <a href="#">个人信息管理</a>
          <dl class="layui-nav-child">
               <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/pwdEdit.jsp" target="option">修改密码</a></dd>
          </dl>
        </li>       
        <li class="layui-nav-item"> 
         <a target="option">订单管理</a>
          <dl class="layui-nav-child">
            <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/studentOrders.jsp" target="option">学生订单</a></dd>
            <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/teacherOrders.jsp" target="option">教师订单</a></dd>
            <dd data-name="edit"><a href="${pageContext.request.contextPath}/manage/orderManageByClassfy.jsp" target="option">根据教材分类</a></dd>
          </dl>
        </li>         
      </ul>
    </div>
  </div>
  <!-- 内容主体区域   采用ajax异步加载-->
  <div class="layui-body" id="LAY_app_body">
   <div class="layadmin-tabsbody-item layui-show"></div>
    <div style="padding: 15px;height:100%"><%-- ${pageContext.request.contextPath}/jsp/orders.jsp --%>
        <iframe id="option" name="option" src="" style="overflow: visible;" scrolling="no" frameborder="no"  width="100%" height="100%">Hello World</iframe>
 </div>
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © itxdl.cn 
  </div>
</div>
</div>
<script>
//JavaScript代码区域
layui.use('element', function(){
  var element = layui.element;  
});
</script>
</body>
</html>

此处只给出2个重要功能代码(学生订单页面和教师订单页面的管理),其余的请联系本人邮箱aaa@qq.com
开荒_TextbookOrderingSystem_管理员页面

学生订单页面jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>教材预定信息</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
  </style>
  <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
</head>
<body>
<table class="layui-hide" id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/js/tool.js"></script>
<script>
layui.use(['laypage', 'layer', 'table', 'element'], function(){
  var $ = layui.jquery
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格  
  ,element = layui.element //元素操作
  ,tableObj = table.render({});
  //执行一个 table 实例
  table.render({
    elem: '#demo'
    ,height: 420
    ,url: '${pageContext.request.contextPath}/manageOrder/studentOrders' //数据接口
    ,limit:5
    //,page:true(自带的这个要注掉)
    ,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
     layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局 
        ,limits:[5,10,15]
        ,first: false //不显示首页
        ,last: false //不显示尾页      
      }
    ,title: '用户表' 
    ,toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
    // ,totalRow: true //开启合计行
    //表头   filed值貌似只可以采用驼峰命名法且与数据实体属性对应
    ,cols: [[ 
           {type: 'checkbox', fixed: 'left'}
              ,{field: 'orderId', title: '订单ID', width:100, sort: true, fixed: 'left', totalRowText: '合计:'}
              ,{field: 'isbn', title: 'ISBN', width:100}
              ,{field: 'bookName', title: '书名', width:100}
              ,{field: 'press', title: '出版社', width:100}
              ,{field: 'auther', title: '作者', width:100}
           ,{field: 'edition', title: '版次', width:100}
           ,{field: 'nature', title: '教材性质', width:100}
           ,{field: 'courseName', title: '课程名', width: 100}
           ,{field: 'className', title: '班级名', width: 100}
           ,{field: 'price', title: '价格', width: 100}
           ,{field: 'count', title: '数量', width: 100}
           ,{field: 'state', title: '订单状态', width: 100}
           ,{field: 'userName', title: '用户名', width:100}
           ,{field: 'phone', title: '手机号', width:100}
           ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
         ]]     
       });
  //监听行工具事件
  table.on('tool(test)', function(obj){ //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event //获得 lay-event 对应的值
    ,editList=[]; 
    $.each(data,function(name,value) {
     editList.push(value); 
  });
    //显示详细信息
    if(layEvent === 'detail'){
      //脚本编辑弹出层   
        var name = encodeURIComponent(data.toolName);
       // console.log(data.toolName);
         layer.open({
            type: 2,
            title: '订单信息', 
            shadeClose: true,
            shade: 0.8,
            maxmin: true,
            area: ['70%', '70%'],
            content: '${pageContext.request.contextPath}/manage/orderInfo.jsp?toolSceneId='+data.toolSceneId+'&'+'id='+data.id,
            success: function(layero, index){  
               var body = layer.getChildFrame('body', index);  
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();  
                var inputList = body.find("input");                
                for (var i = 0; i < inputList.length; i++ ) {  
                  $(inputList[i]).val(editList[i]);  
                }    
            }   
 });      
    } else if(layEvent === 'del'){
      layer.confirm('真的删除行么', function(index){     
        //向服务端发送删除指令
        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/manageOrder/delOrder",
            dataType:'json',
           // async: false, 
            data: "id="+data.orderId,
            dataType: "json",
            success: function (data) { 
                var message = data.msg; 
                if(data.msg== '1'){ 
                 obj.del(); 
                    layer.close(index);
                    layer.alert("删除成功",{icon: 1,time:2000});
                    tableObj.reload({
                       url:'${pageContext.request.contextPath}/manageOrder/manageOrder'
                    });
                } else {
                    layer.alert("删除失败", {
                        icon: 2,title:'提示'
                    });
                    return;
                }
            },
            error: function () {
            }
        });
      });
    } else if(layEvent === 'edit'){ 
       //脚本编辑弹出层
            var name = encodeURIComponent(data.toolName);
           // console.log(data.toolName);
             layer.open({
                type: 2,
                title: '编辑订单信息', 
                shadeClose: true,
                shade: 0.8,
                maxmin: true,
                area: ['70%', '70%'],
                content: '${pageContext.request.contextPath}/manage/orderEdit.jsp?toolSceneId='+data.toolSceneId+'&'+'id='+data.id,
                success: function(layero, index){  
                   var body = layer.getChildFrame('body', index);  
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();  
                    var inputList = body.find("input");              
                    for (var i = 0; i < inputList.length; i++ ) {  
                      $(inputList[i]).val(editList[i]);  
                    }       
                  }   
        }); 
     }
   });
});
</script>
</body>
</html>          

教师订单jsp页面

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>教材预定信息</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
  </style>
  <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
</head>
<body>
<table class="layui-hide" id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> 
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/js/tool.js"></script>
<script>
layui.use(['laypage', 'layer', 'table', 'element'], function(){
  var $ = layui.jquery
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格  
  ,element = layui.element //元素操作
  ,tableObj = table.render({});
  //执行一个 table 实例
  table.render({
    elem: '#demo'
    ,height: 420
    ,url: '${pageContext.request.contextPath}/manageOrder/teacherOrders' //数据接口
    ,limit:5
    //,page:true(自带的这个要注掉)
    ,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
     layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局 
        ,limits:[5,10,15]
        ,first: false //不显示首页
        ,last: false //不显示尾页    
      }
    ,title: '用户表' 
    ,toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
    // ,totalRow: true //开启合计行
    //表头   filed值貌似只可以采用驼峰命名法且与数据实体属性对应
    ,cols: [[ 
           {type: 'checkbox', fixed: 'left'}
              ,{field: 'orderId', title: '订单ID', width:100, sort: true, fixed: 'left', totalRowText: '合计:'}
              ,{field: 'isbn', title: 'ISBN', width:100}
              ,{field: 'bookName', title: '书名', width:100}
              ,{field: 'press', title: '出版社', width:100}
              ,{field: 'auther', title: '作者', width:100}
           ,{field: 'edition', title: '版次', width:100}
           ,{field: 'nature', title: '教材性质', width:100}
           ,{field: 'courseName', title: '课程名', width: 100}
           ,{field: 'className', title: '班级名', width: 100}
           ,{field: 'price', title: '价格', width: 100}
           ,{field: 'count', title: '数量', width: 100}
           ,{field: 'state', title: '订单状态', width: 100}
           ,{field: 'userName', title: '用户名', width:100}
           ,{field: 'phone', title: '手机号', width:100}
           ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
         ]]   
       });
  //监听行工具事件
  table.on('tool(test)', function(obj){ //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event //获得 lay-event 对应的值
    ,editList=[]; 
    $.each(data,function(name,value) {
     editList.push(value);  
  }); 
    //显示详细信息
    if(layEvent === 'detail'){
      //脚本编辑弹出层   
        var name = encodeURIComponent(data.toolName);
       // console.log(data.toolName);
         layer.open({
            type: 2,
            title: '订单信息', 
            shadeClose: true,
            shade: 0.8,
            maxmin: true,
            area: ['70%', '70%'],
            content: '${pageContext.request.contextPath}/manage/orderInfo.jsp?toolSceneId='+data.toolSceneId+'&'+'id='+data.id,
            success: function(layero, index){  
               var body = layer.getChildFrame('body', index);  
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();  
                var inputList = body.find("input");                
                for (var i = 0; i < inputList.length; i++ ) {  
                  $(inputList[i]).val(editList[i]);  
                }    
            }   
 });     
    } else if(layEvent === 'del'){
      layer.confirm('真的删除行么', function(index){        
        //向服务端发送删除指令
        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/manageOrder/delOrder",
            dataType:'json',
           // async: false, 
            data: "id="+data.orderId,
            dataType: "json",
            success: function (data) { 
                var message = data.msg; 
                if(data.msg== '1'){ 
                 obj.del(); 
                    layer.close(index);
                    layer.alert("删除成功",{icon: 1,time:2000});
                    tableObj.reload({
                       url:'${pageContext.request.contextPath}/manageOrder/manageOrder'
                    });
                } else {
                    layer.alert("删除失败", {
                        icon: 2,title:'提示'
                    });
                    return;
                }
            },
            error: function () {
            }
        });
      });
    } else if(layEvent === 'edit'){ 
       //脚本编辑弹出层
            var name = encodeURIComponent(data.toolName);
           // console.log(data.toolName);
             layer.open({
                type: 2,
                title: '编辑订单信息', 
                shadeClose: true,
                shade: 0.8,
                maxmin: true,
                area: ['70%', '70%'],
                content: '${pageContext.request.contextPath}/manage/orderEdit.jsp?toolSceneId='+data.toolSceneId+'&'+'id='+data.id,
                success: function(layero, index){  
                   var body = layer.getChildFrame('body', index);  
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();  
                    var inputList = body.find("input");        
                    for (var i = 0; i < inputList.length; i++ ) {  
                      $(inputList[i]).val(editList[i]);  
                    }       
                  }   
        });      
     }
   });   
});
</script>
</body>
</html>            

controller

@Controller
@RequestMapping("manageOrder")
public class ManageOrdersController {
 @Autowired
 ManageService manageService;
 // 显示学生信息
 @ResponseBody
 @RequestMapping("studentOrders")
 public Map<String, Object> studentOrders(int page, int limit) {
  // 订单数量用于分页
  int count = manageService.getOrdersCount("student");
  // 获取当前页的记录
  List<ManageOrders> orders = manageService.getStudentOrders(page, limit);
  Map<String, Object> tableData = new HashMap<String, Object>();
  tableData.put("code", 0);
  tableData.put("msg", "");
  tableData.put("count", count);
  tableData.put("data", orders);
  System.out.println("tableData:" + tableData);
  return tableData;
 }
 //显示教师订单信息
 @ResponseBody
 @RequestMapping("teacherOrders")
 public Map<String, Object> teacherOrders(int page, int limit) {
  // 订单数量用于分页
  int count = manageService.getOrdersCount("teacher");
  // 获取当前页的记录
  List<ManageOrders> orders = manageService.getTeacherOrders(page, limit);
  Map<String, Object> tableData = new HashMap<String, Object>();
  tableData.put("code", 0);
  tableData.put("msg", "");
  tableData.put("count", count);
  tableData.put("data", orders);
  System.out.println("tableData:" + tableData);
  return tableData;
 }
 //修改订单
 @ResponseBody
 @RequestMapping("editOrder")
 public Map<String, String> editOrder(ManageOrders order) {
  Map<String, String> data = new HashMap<String, String>();
  int result = manageService.editOrder(order);
  if (result > 0) {
   data.put("msg", "1");
  } else {
   data.put("msg", "0");
  }
  return data;
 } 
 //删除订单
 @ResponseBody
 @RequestMapping("delOrder")
 public Map<String, String> delOrder(int id) {  
  int result = 0;
  result = manageService.delOrder(id);
  Map<String, String> data = new HashMap<String, String>();
  if (result > 0) {
   data.put("msg", "1");
  } else {
   data.put("msg", "0");
  }
  return data;
 }
}

service

/**
 * 业务层
 * 
 * @author guai
 *
 */
@Service
public class ManageService {
 @Autowired
 ManageOrdersDao manageOrdersDao; 
 /**
  * 获取订单总数
  * @param postion student  or teacher
  * @return
  */
 public int getOrdersCount(String postion) {
  // TODO Auto-generated method stub
  return manageOrdersDao.getOrdersCount(postion);
 }
 /**
  * 获取学生订单
  * @param page
  * @param limit
  * @return
  */
 public List<ManageOrders> getStudentOrders(int page, int limit) {
  return manageOrdersDao.getStudentOrders(page, limit);
 } 
 /**
  * 获取教师订单
  * @param page
  * @param limit
  * @return
  */
 public List<ManageOrders> getTeacherOrders(int page, int limit) {
  return manageOrdersDao.getTeacherOrders(page, limit);
 }
 /**
  * 修改订单信息
  * @param order
  * @return
  */
 public int editOrder(ManageOrders order) {
  return manageOrdersDao.editOrder(order);
 } 
 /**
  *删除订单
  * @param id
  * @return
  */
 public int delOrder(int id) {
  return manageOrdersDao.delOrder(id);
 } 
 /**
  * 修改订单
  * @param order
  * @return
  *//*
 public int editOrder(ManageOrders order) {
  return manageOrdersDao.editOrder(order);
 }
 *//**
  * 删除订单
  * @param id
  * @return
  *//*
 public int delOrder(int id) {
  return manageOrdersDao.delOrder(id);
 }
 public List<ManageOrders> getOrdersByStatus(int page, int limit) {
  // TODO Auto-generated method stub
  return manageOrdersDao.getOrdersByStatus(page, limit);
 }
*/
}

entity

public class ManageOrders {
 private Integer orderId;
 private String isbn;
 private String bookName;
 // 出版社
 private String press;
 private String auther;
 // 版次
 private String edition;
 // 教材性质
 private String nature;
 private String courseName;
 private String className;
 private BigDecimal price;
 private Integer count;
 // 订单状态
 private String state;
 private String userName;
 private String phone;
 public ManageOrders() {
  super();
 }
 public ManageOrders(Integer orderId, String isbn, String bookName, String press, String auther, String edition,
   String nature, String courseName, String className, BigDecimal price, Integer count, String state,
   String userName, String phone) {
  super();
  this.orderId = orderId;
  this.isbn = isbn;
  this.bookName = bookName;
  this.press = press;
  this.auther = auther;
  this.edition = edition;
  this.nature = nature;
  this.courseName = courseName;
  this.className = className;
  this.price = price;
  this.count = count;
  this.state = state;
  this.userName = userName;
  this.phone = phone;
 }
 public Integer getOrderId() {
  return orderId;
 }
 public void setOrderId(Integer orderId) {
  this.orderId = orderId;
 }
 public String getIsbn() {
  return isbn;
 }
 public void setIsbn(String isbn) {
  this.isbn = isbn;
 }
 public String getBookName() {
  return bookName;
 }
 public void setBookName(String bookName) {
  this.bookName = bookName;
 }
 public String getPress() {
  return press;
 }
 public void setPress(String press) {
  this.press = press;
 }
 public String getAuther() {
  return auther;
 }
 public void setAuther(String auther) {
  this.auther = auther;
 }
 public String getEdition() {
  return edition;
 }
 public void setEdition(String edition) {
  this.edition = edition;
 }
 public String getNature() {
  return nature;
 }
 public void setNature(String nature) {
  this.nature = nature;
 }
 public String getCourseName() {
  return courseName;
 }
 public void setCourseName(String courseName) {
  this.courseName = courseName;
 }
 public String getClassName() {
  return className;
 }
 public void setClassName(String className) {
  this.className = className;
 }
 public BigDecimal getPrice() {
  return price;
 }
 public void setPrice(BigDecimal price) {
  this.price = price;
 }
 public Integer getCount() {
  return count;
 }
 public void setCount(Integer count) {
  this.count = count;
 }
 public String getState() {
  return state;
 }
 public void setState(String state) {
  this.state = state;
 }
 public String getUserName() {
  return userName;
 }
 public void setUserName(String userName) {
  this.userName = userName;
 }
 public String getPhone() {
  return phone;
 }
 public void setPhone(String phone) {
  this.phone = phone;
 }
 @Override
 public String toString() {
  return "ManageOrders [orderId=" + orderId + ", isbn=" + isbn + ", bookName=" + bookName + ", press=" + press
    + ", auther=" + auther + ", edition=" + edition + ", nature=" + nature + ", courseName=" + courseName
    + ", className=" + className + ", price=" + price + ", count=" + count + ", state=" + state
    + ", userName=" + userName + ", phone=" + phone + "]";
 } 
}

dao接口

/**
 * 持久层接口
 * @author guai
 *
 */
@Component
public interface ManageOrdersDao {
 /**
  * 获取订单总数
  * @param postion 教师or学生
  * @return
  */
 int getOrdersCount(String postion);
 /**
  * 获取当学生订单
  * @param page
  * @param limit
  * @returnList<ManageOrders>
  */
 List<ManageOrders> getStudentOrders(int page, int limit);
 /**
  * 获取教师订单
  * @param page
  * @param limit
  * @return
  */
 List<ManageOrders> getTeacherOrders(int page, int limit);
  /**
   * 修改订单信息
   * @param order
   * @return
   */
 int editOrder(ManageOrders order);
 /**
  * 删除订单
  * @param id
  * @return
  */
 int delOrder(int id); 
 /**
  * 获取当前页未处理订单
  * @param page
  * @param limit
  * @returnList<ManageOrders>
  */
 /*List<ManageOrders> getOrdersByStatus(int page, int limit);
 *//**
  * 修改订单
  * @param order
  * @return int
  *//*
 int editOrder(ManageOrders order);
 *//**
  * 删除订单
  * @param id
  * @return int
  *//*
 int delOrder(int id);*/
}

daoimpl

@Repository
public class ManageOrdersDaoImpl implements ManageOrdersDao {
 //依赖注入
 @Autowired
 JdbcTemplate jdbcTemplate; 
 @Override
 public int getOrdersCount(String postion) {
  // TODO Auto-generated method stub
  if("student".equals(postion)) {
   String sql="select count(*) from student_order";
   return jdbcTemplate.queryForObject(sql, Integer.class);
  }else if("teacher".equals(postion)) {
   String sql="select count(*) from teacher_order";
   return jdbcTemplate.queryForObject(sql, Integer.class);
  }else {
   return 0;
  }  
 }
 @Override
 public List<ManageOrders> getStudentOrders(int page, int limit) {
  // TODO Auto-generated method stub
  int start=(page-1)*limit;
  //查询数据库表userorder中从start行开始到pageSize行的所有订单
  String sql="select * from student_order limit ?,?";
  //映射结果集ResultSet的行的接口。该接口的实现,将每行数据映射到实例对象 
  RowMapper<ManageOrders> rowMapper=new BeanPropertyRowMapper<ManageOrders>(ManageOrders.class);
  List<ManageOrders> manageOrders=jdbcTemplate.query(sql,rowMapper,start,limit);
  return manageOrders;
 }
 @Override
 public List<ManageOrders> getTeacherOrders(int page, int limit) {
  // TODO Auto-generated method stub
  int start=(page-1)*limit;
  //查询数据库表userorder中从start行开始到pageSize行的所有订单
  String sql="select * from teacher_order limit ?,?";
  //映射结果集ResultSet的行的接口。该接口的实现,将每行数据映射到实例对象 
  RowMapper<ManageOrders> rowMapper=new BeanPropertyRowMapper<ManageOrders>(ManageOrders.class);
  List<ManageOrders> manageOrders=jdbcTemplate.query(sql,rowMapper,start,limit);
  return manageOrders;
 }
 @Override
 public int editOrder(ManageOrders order) {
  // TODO Auto-generated method stub
  System.out.println(order.toString());
  String sql="select count(*) from book_info where isbn=?";
  int result=0;
  result=jdbcTemplate.queryForObject(sql, Integer.class,order.getIsbn()); 
  //如果book_info表中存在该书则只用修改wanted表
  if(result>0) {
   result=0;
   sql="update orders set isbn=?,price=?,count=?,className=?,courseName=?,state=? where orderId=?";
   result=jdbcTemplate.update(sql,order.getIsbn(),order.getPrice(),order.getCount(),order.getClassName(),order.getCourseName(),order.getState(),order.getOrderId());
  }else {
   //如果books表中不存在该书则添加该书并修改wanted表
   sql="insert into book_info values(?,?,?,?,?,?,?)";
   result=jdbcTemplate.update(sql,order.getIsbn(),order.getBookName(),order.getPress(),order.getAuther(),order.getEdition(),order.getNature(),order.getPrice());
   if(result>0) {
    sql="update orders set isbn=?,price=?,count=?,className=?,courseName=?,state=? where orderId=?";
    result=jdbcTemplate.update(sql,order.getIsbn(),order.getPrice(),order.getCount(),order.getClassName(),order.getCourseName(),order.getState(),order.getOrderId());
   }
  } 
  return result;
 }
 @Override
 public int delOrder(int id) {
  // TODO Auto-generated method stub
        String sql="delete from orders where orderID=?"; 
  return jdbcTemplate.update(sql,id);
 }
}
如需源码请联系本人邮箱:1103325500@qq.com
相关标签: 项目