码迷,mamicode.com
首页 > 其他好文 > 详细

表达式

时间:2014-11-04 16:54:31      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   java   

struts标签 jstl标签 OGNL表达式 EL表达式

前台显示:

<%@page import="runtong.entity.Orders"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>33润通官网</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/index.css" />
<script src="js/jquery-1.4.3.min.js"></script>
<script language="javascript">
    $(document).ready(function() { //这个就是传说的ready   
        $(".stripe tr").mouseover(function() {
            //如果鼠标移到class为stripe的表格的tr上时,执行函数   
            $(this).addClass("over");
        }).mouseout(function() {
            //给这行添加class值为over,并且当鼠标一出该行时执行函数   
            $(this).removeClass("over");
        }) //移除该行的class   
        $(".stripe tr:even").addClass("alt");
        //给class为stripe的表格的偶数行添加class值为alt
        //www.divcss5.com 整理特效
    });
    $("#c-nav>li").each(function() {
        $(this).hover(function() {
            $(this).children(".c-sub").css("display", "block");
            $(this).children(".c-sub").animate({
                opacity : "1",
                top : "100%"
            }, 240);
        }, function() {
            $(this).children(".c-sub").css({
                display : "none",
                opacity : "0",
                top : "60%"
            });
        });
    })
</script>
</head>

<body>
    <jsp:include page="head.jsp"></jsp:include>
    <div class="fatbar">
        <h2 class="fatbar-title personal-title">个人中心</h2>
    </div>

    <!--产品详情页-->
    <div class="wrap">
        <div class="showlist">
            <div class="ll-box">
                <div class="order">
                    <p class="ptext">订单详情</p>
                    <form action="" method="get">
                        <table border="1" class="stripe">
                            <tr style="height:40px;text-align:center;">
                                <th style="display:none;">id</th>
                                <th>收货人姓名</th>
                                <th>收货人手机号码</th>
                                <th>数量</th>
                                <th>金额</th>
                                <th>收货人地址</th>
                                <th>添加时间</th>
                                <th>支付状态</th>
                                <th></th>
                            </tr>
                            <s:iterator value="#request.orders.results" var="order">
                                <tr>
                                    <td style="display:none">${order.id}</td>
                                    <td>${order.receivename}</td>
                                    <td>${order.receivemobile}</td>
                                    <td>${order.count}</td>
                                    <td>${order.money}</td>
                                    <td>${order.address}</td>
                                    <td>${order.addTime}</td>
                                    <c:if test="${order.status==‘0‘}">
                                        <td>未付款</td>
                                    </c:if>
                                    <c:if test="${order.status==‘1‘}">
                                        <td>已付款</td>
                                    </c:if>
                                    <c:if test="${order.status==‘0‘}">
                                        <td><a
                                            href="updateOrderStatus?id=${order.id}&money=${order.money}">支付</a></td>
                                    </c:if>
                                </tr>
                            </s:iterator>
                        </table>
                    </form>
                    <p>
                        <a> <s:property value=‘#request.orders.pageIndex‘ />页/<s:property value=‘#request.orders.pageCount‘ /></a>
                        <s:if test="#request.orders.pageIndex > 1">
                            <a href="orderlist?pageIndex=1" title="首页">首页</a>
                            <a href="orderlist?pageIndex=<s:property value=‘#request.orders.pageIndex-1‘/>" title="上一页">上页 
                        </s:if>
                        <s:if test="#request.orders.pageIndex<#request.orders.pageCount">
                       <a href="orderlist?pageIndex=<s:property value=‘#request.orders.pageIndex+1‘/>" title="下一页">下页 
<a href="orderlist?pageIndex=<s:property value=‘#request.orders.pageCount‘/>" title="末页">末页</a> </s:if> </div> </div> <div class="rr-box"></div> </div> </div> <div class="clear"></div> <jsp:include page="foot.jsp"></jsp:include> </body> </html>

PageBean.java

package runtong.util;

import java.util.List;

public class PageBean {

    private int pageIndex;
    private int pageSize;
    private int rowCount;
    private int pageCount;
    private List results;

    public int getPageIndex() {
        return pageIndex;
    }
    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getRowCount() {
        return rowCount;
    }
    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
    }
    public int getPageCount() {
        return pageCount;
    }
    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }
    public List getResults() {
        return results;
    }
    public void setResults(List results) {
        this.results = results;
    }
    
}

OrderListAction.java

package runtong.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import runtong.dao.IOrdersDAO;
import runtong.dao.OrdersDAOImpl;
import runtong.entity.Orders;
import runtong.entity.Users;
import runtong.util.PageBean;

public class OrderListAction extends BaseAction {
    private IOrdersDAO ordersDAO = new OrdersDAOImpl();
    private int pageIndex=1;
    private int pageSize=4;

    @Override
    public String execute() throws Exception {
        Users users = (Users) sessionMap.get("user");
        PageBean orders = ordersDAO.list(users.getId(), pageIndex, pageSize);
        requestMap.put("orders", orders);
        return SUCCESS;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    

}

OrdersDAOImpl.java

package runtong.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import runtong.entity.Orders;
import runtong.util.HibernateUtil;
import runtong.util.PageBean;

public class OrdersDAOImpl implements IOrdersDAO {

    @Override
    //保存订单
    public boolean save(Orders orders) {
        boolean success=true;
        Session session=null;
        Transaction tc=null;
        try {
            session=HibernateUtil.getSession();
            tc=session.beginTransaction();
            session.save(orders);
            tc.commit();
        } catch (Exception e) {
            success=false;
            tc.rollback();
            throw new RuntimeException(e);
        }
        finally{
            HibernateUtil.closeSession();
        }
        return success;
    }

    @Override
    //根据订单id获取订单
    public Orders get(int id) {
        Orders orders=null;
        Session session=null;
        try {
            session=HibernateUtil.getSession();
            orders=(Orders)session.get(Orders.class,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        finally{
            HibernateUtil.closeSession();
        }        
        return orders;
    }

    @Override
    //更新订单
    public boolean update(Orders orders) {
        boolean success=true;
        Session session=null;
        Transaction tc=null;
        try {
            session=HibernateUtil.getSession();
            tc=session.beginTransaction();
            session.update(orders);
            tc.commit();
        } catch (Exception e) {
            success=false;
            tc.rollback();
            throw new RuntimeException(e);
        }
        finally{
            HibernateUtil.closeSession();
        }
        return success;
    }
    
    @Override
    public boolean delete(int id) {
        boolean success=true;
        Session session=null;
        Transaction tc=null;
        try {
            session=HibernateUtil.getSession();
            tc=session.beginTransaction();
            Orders orders=(Orders)session.load(Orders.class, id);
            session.delete(orders);
        } catch (Exception e) {
            success=false;
            tc.rollback();
            throw new RuntimeException(e);
            
        }finally{
            HibernateUtil.closeSession();
        }
        return success;
    }

    @Override
    //获取所有订单,分页
    public PageBean list(int pageIndex, int pageSize) {
        PageBean pageBean=new PageBean();
        Session session=null;
        try {
            session=HibernateUtil.getSession();
            //查询总行数
            int rowCount= ((Number)session.createQuery("select count(*) from Orders").uniqueResult()).intValue();
            //计算总页数
            
            int pageCount=(rowCount%pageSize==0)?(rowCount/pageSize):(rowCount/pageSize+1);
            if(pageCount==0){
                pageCount=1;
            }
            //计算当前页第一条数据的行号
            int firstResult=(pageIndex-1)*pageSize;
            //查询分页列表
            List<Orders> results=session.createQuery("from Orders o order by o.id")
                      .setFirstResult(firstResult)
                      .setMaxResults(pageSize)
                      .list();
            
            pageBean.setPageIndex(pageIndex);
            pageBean.setPageSize(pageSize);
            pageBean.setRowCount(rowCount);
            pageBean.setPageCount(pageCount);
            pageBean.setResults(results);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        finally{
            HibernateUtil.closeSession();
        }                
        return pageBean;
        
    }

    @Override
    public List list(int uid) {
        // TODO Auto-generated method stub
        Session session = null;
        session = HibernateUtil.getSession();
        List myorders = null;
        myorders = session.createQuery("from Orders o where uid=? order by o.uid").setInteger(0, uid).list();
        return myorders;
    }

    @Override
    public PageBean list(int uid, int pageIndex, int pageSize) {
        // TODO Auto-generated method stub
        PageBean pageBean=new PageBean();
        Session session=null;
        try {
            session=HibernateUtil.getSession();
            //查询总行数
            int rowCount= ((Number)session.createQuery("select count(*) from Orders where uid=?").setInteger(0, uid).uniqueResult()).intValue();
            //计算总页数
            int pageCount=(rowCount%pageSize==0)?(rowCount/pageSize):(rowCount/pageSize+1);
            if(pageCount==0){
                pageCount=1;
            }
            //计算当前页第一条数据的行号
            int firstResult=(pageIndex-1)*pageSize;
            //查询分页列表
            List<Orders> results=session.createQuery("from Orders o where uid=? order by o.id").setInteger(0, uid).setFirstResult(firstResult).setMaxResults(pageSize).list();
            pageBean.setPageIndex(pageIndex);
            pageBean.setPageSize(pageSize);
            pageBean.setRowCount(rowCount);
            pageBean.setPageCount(pageCount);
            pageBean.setResults(results);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        finally{
            HibernateUtil.closeSession();
        }                
        return pageBean;
    }

    
}

 

表达式

标签:des   style   blog   http   io   color   ar   os   java   

原文地址:http://www.cnblogs.com/manusas/p/4073779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!