public class Product{ private int pid; private String productName; private String author; private double price; private Date publishTime; private String descript; private String imgSrc; private String remark; private Category category = new Category(); public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Date getPublishTime() { return publishTime; } public void setPublishTime(Date publishTime) { this.publishTime = publishTime; } public String getDescript() { return descript; } public void setDescript(String descript) { this.descript = descript; } public String getImgSrc() { return imgSrc; } public void setImgSrc(String imgSrc) { this.imgSrc = imgSrc; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; } } 表结构和上面是一样的 product.xml <sqlMap namespace="Product"> <typeAlias alias="product" type="org.bs.pojo.Product" /> <typeAlias alias="category" type="org.bs.pojo.Category" /> <resultMap class="category" id="categoryMap"> <result property="cid" column="cid" /> <result property="categoryName" column="categoryName" /> </resultMap> <resultMap class="product" id="productMap"> <result property="pid" column="pid" /> <result property="productName" column="productName" /> <result property="author" column="author" /> <result property="price" column="price" /> <result property="publishTime" column="publishTime" /> <result property="descript" column="descript" /> <result property="imgSrc" column="imgSrc" /> <result property="remark" column="remark" /> <result property="category" column="cid" select="getCategoryById" /> </resultMap> <select id="getCategoryById" resultClass="category"> select cid,categoryName from category </select> <select id="getAllProduct" resultClass="product"> select * from product </select> </sqlMap> dao public class ProductDaoImpl extends SqlMapClientDaoSupport implements IProductDao { public List<Product> getAllProduct() { List<Product> listProduct = getSqlMapClientTemplate().queryForList( "getAllProduct"); return listProduct; } } test调用 @Test public void testProduct() { IProductBiz u = (IProductBiz) GetBean.getBean("productBiz"); try { List<Product> list = u.getAllProduct(); for (int i = 0; i < list.size(); i++) { Product p = list.get(i); System.out.println(p.getProductName()+ p.getCategory().getCid()); } } catch (Exception e) { e.printStackTrace(); } }