_潜伏者_ 2015-02-11 02:48 采纳率: 66.7%
浏览 1770

SSH2框架 我想用ognl标签获取另一对象的属性!

Goodsinfo.java

package ssh2.jxc.wjr.vo;

import java.util.HashSet;
import java.util.Set;

/**
 * Goodsinfo entity. @author MyEclipse Persistence Tools
 */

public class Goodsinfo implements java.io.Serializable {

    // Fields

    private Integer gid;
    private Goodsclassinfo goodsclassinfo;
    private String gname;
    private Integer gamount;
    private String gunit;
    private Double gpin;
    private Double gpout;
    private Set selldetails = new HashSet(0);
    private Set consumerbackdetails = new HashSet(0);
    private Set providerbackdetails = new HashSet(0);
    private Set stockdetails = new HashSet(0);

    // Constructors

    /** default constructor */
    public Goodsinfo() {
    }

    /** minimal constructor */
    public Goodsinfo(Goodsclassinfo goodsclassinfo, Integer gamount) {
        this.goodsclassinfo = goodsclassinfo;
        this.gamount = gamount;
    }

    /** full constructor */
    public Goodsinfo(Goodsclassinfo goodsclassinfo, String gname,
            Integer gamount, String gunit, Double gpin, Double gpout,
            Set selldetails, Set consumerbackdetails, Set providerbackdetails,
            Set stockdetails) {
        this.goodsclassinfo = goodsclassinfo;
        this.gname = gname;
        this.gamount = gamount;
        this.gunit = gunit;
        this.gpin = gpin;
        this.gpout = gpout;
        this.selldetails = selldetails;
        this.consumerbackdetails = consumerbackdetails;
        this.providerbackdetails = providerbackdetails;
        this.stockdetails = stockdetails;
    }

    // Property accessors

    public Integer getGid() {
        return this.gid;
    }

    public void setGid(Integer gid) {
        this.gid = gid;
    }

    public Goodsclassinfo getGoodsclassinfo() {
        return this.goodsclassinfo;
    }

    public void setGoodsclassinfo(Goodsclassinfo goodsclassinfo) {
        this.goodsclassinfo = goodsclassinfo;
    }

    public String getGname() {
        return this.gname;
    }

    public void setGname(String gname) {
        this.gname = gname;
    }

    public Integer getGamount() {
        return this.gamount;
    }

    public void setGamount(Integer gamount) {
        this.gamount = gamount;
    }

    public String getGunit() {
        return this.gunit;
    }

    public void setGunit(String gunit) {
        this.gunit = gunit;
    }

    public Double getGpin() {
        return this.gpin;
    }

    public void setGpin(Double gpin) {
        this.gpin = gpin;
    }

    public Double getGpout() {
        return this.gpout;
    }

    public void setGpout(Double gpout) {
        this.gpout = gpout;
    }

    public Set getSelldetails() {
        return this.selldetails;
    }

    public void setSelldetails(Set selldetails) {
        this.selldetails = selldetails;
    }

    public Set getConsumerbackdetails() {
        return this.consumerbackdetails;
    }

    public void setConsumerbackdetails(Set consumerbackdetails) {
        this.consumerbackdetails = consumerbackdetails;
    }

    public Set getProviderbackdetails() {
        return this.providerbackdetails;
    }

    public void setProviderbackdetails(Set providerbackdetails) {
        this.providerbackdetails = providerbackdetails;
    }

    public Set getStockdetails() {
        return this.stockdetails;
    }

    public void setStockdetails(Set stockdetails) {
        this.stockdetails = stockdetails;
    }

}

Goodsclassinfo.java

 package ssh2.jxc.wjr.vo;

import java.util.HashSet;
import java.util.Set;

/**
 * Goodsclassinfo entity. @author MyEclipse Persistence Tools
 */

public class Goodsclassinfo implements java.io.Serializable {

    // Fields

    private Integer gcid;
    private String gcname;
    private Set goodsinfos = new HashSet(0);

    // Constructors

    /** default constructor */
    public Goodsclassinfo() {
    }

    /** minimal constructor */
    public Goodsclassinfo(String gcname) {
        this.gcname = gcname;
    }

    /** full constructor */
    public Goodsclassinfo(String gcname, Set goodsinfos) {
        this.gcname = gcname;
        this.goodsinfos = goodsinfos;
    }

    // Property accessors

    public Integer getGcid() {
        return this.gcid;
    }

    public void setGcid(Integer gcid) {
        this.gcid = gcid;
    }

    public String getGcname() {
        return this.gcname;
    }

    public void setGcname(String gcname) {
        this.gcname = gcname;
    }

    public Set getGoodsinfos() {
        return this.goodsinfos;
    }

    public void setGoodsinfos(Set goodsinfos) {
        this.goodsinfos = goodsinfos;
    }

}

GoodsinfoDAO.java

 package ssh2.jxc.wjr.dao.impl;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import ssh2.jxc.wjr.dao.IGoodsinfoDAO;
import ssh2.jxc.wjr.vo.Goodsinfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * Goodsinfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see ssh2.jxc.wjr.vo.Goodsinfo
 * @author MyEclipse Persistence Tools
 */
@Repository
public class GoodsinfoDAO extends HibernateDaoSupport implements IGoodsinfoDAO {
    private static final Logger log = LoggerFactory
            .getLogger(GoodsinfoDAO.class);
    // property constants
    public static final String GNAME = "gname";
    public static final String GAMOUNT = "gamount";
    public static final String GUNIT = "gunit";
    public static final String GPIN = "gpin";
    public static final String GPOUT = "gpout";


    @Resource  
    public void setSessionFactoryOverride(SessionFactory sessionFactory) {   
      super.setSessionFactory(sessionFactory);   
    } 

    protected void initDao() {
        // do nothing
    }

    public void save(Goodsinfo transientInstance) {
        log.debug("saving Goodsinfo instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

    public void delete(Goodsinfo persistentInstance) {
        log.debug("deleting Goodsinfo instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Goodsinfo findById(java.lang.Integer id) {
        log.debug("getting Goodsinfo instance with id: " + id);
        try {
            Goodsinfo instance = (Goodsinfo) getHibernateTemplate().get(
                    "ssh2.jxc.wjr.vo.Goodsinfo", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(Goodsinfo instance) {
        log.debug("finding Goodsinfo instance by example");
        try {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: "
                    + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }

    public List findByProperty(String propertyName, Object value) {
        log.debug("finding Goodsinfo instance with property: " + propertyName
                + ", value: " + value);
        try {
            String queryString = "from Goodsinfo as model where model."
                    + propertyName + "= ?";
            return getHibernateTemplate().find(queryString, value);
        } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    public List findByGname(Object gname) {
        return findByProperty(GNAME, gname);
    }

    public List findByGamount(Object gamount) {
        return findByProperty(GAMOUNT, gamount);
    }

    public List findByGunit(Object gunit) {
        return findByProperty(GUNIT, gunit);
    }

    public List findByGpin(Object gpin) {
        return findByProperty(GPIN, gpin);
    }

    public List findByGpout(Object gpout) {
        return findByProperty(GPOUT, gpout);
    }

    public List findAll() {
        log.debug("finding all Goodsinfo instances");
        try {
            String queryString = "from Goodsinfo";
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    public Goodsinfo merge(Goodsinfo detachedInstance) {
        log.debug("merging Goodsinfo instance");
        try {
            Goodsinfo result = (Goodsinfo) getHibernateTemplate().merge(
                    detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Goodsinfo instance) {
        log.debug("attaching dirty Goodsinfo instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(Goodsinfo instance) {
        log.debug("attaching clean Goodsinfo instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public static IGoodsinfoDAO getFromApplicationContext(ApplicationContext ctx) {
        return (IGoodsinfoDAO) ctx.getBean("GoodsinfoDAO");
    }

    //获取全部商品信息
    @Override
    public List getGoodsinfos() {
        String hql="from Goodsinfo";

        Session session=getHibernateTemplate().getSessionFactory().openSession();

        Query query=session.createQuery(hql);
        List<Goodsinfo> goodsinfos=query.list();

        //test
        System.out.println(goodsinfos.iterator().next().getGoodsclassinfo().getGcname());

        session.close();

        return goodsinfos;
    }
}

goodsmanger.jsp

 <s:iterator value="#request['goodsinfos']" id="goodsinfos" status="iteratorStatus">
    <s:if test="!#iteratorStatus.odd">
      <tr bgcolor="white" align="center">
        <td><s:property value="#goodsinfos.gname" /></td><!-- 显示商品名称 -->
        <td><s:property value="#goodsinfos.goodsclassinfos" /></td><!-- 显示商品类别 -->
        <td>¥<s:property value="#goodsinfos.gpin" /></td><!-- 进价 -->
        <td>¥<s:property value="#goodsinfos.gpout" /></td><!-- 售价 -->
        <td><s:property value="#goodsinfos.gunit" /></td><!-- 计价单位 -->
        <td><s:property value="#goodsinfos.gamount" /></td><!-- 商品数量 -->
        <td width="120">
            gid:<s:property value="gid" />
            <a href="#" target="mainFrame">
                <img border="0" src="img/mod.gif" height="16" width="16"/>查看/修改
            </a>
        </td>
        <td width="100">
            <a href="#">
                <img border="0" src="img/del.gif"/>删除
            </a>
        </td>
      </tr>
      </s:if>

我的思路是 List goodsinfo 存到 Map request
在页面上就可以获取到 goodsinfo类的属性值,
就是没有办法获取到商品类别(

<!-- 显示商品类别 -->:没有办法显示)

问题所在:可以获取到对象 goodsinfos (List)里面的每一个对象goodsinfo里面的属性。
就是获取不到 goodsclassinfo的属性的gcname。
我使用的这段代码可以获取到 商品的类别

截取

 System.out.println(goodsinfos.iterator().next().getGoodsclassinfo().getGcname());

求解?

  • 写回答

2条回答 默认 最新

  • 消失地旧时光 2015-02-11 09:18
    关注

    改成

    <!-- 显示商品类别 -->
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况