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个回答

改成

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

代码还给我屏蔽了。。奶奶的。
把value="#goodsinfos.goodsclassinfos" 改成 value="#goodsinfos.goodsclassinfos.gcname"


u012898211
_潜伏者_ 回复u012898211: System.out.println(goodsinfos.iterator().next().getGoodsclassinfo().getGcname());
接近 5 年之前 回复
u012898211
_潜伏者_ 我在后台:使用的 这段代码可以获取到 商品类里面的商品类别对象的属性商品类别名
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问