实现mybatis单表查询分类
< resultMap id= "BaseResultMap3" type= "com.ynbw.goodsserver.entity.GoodsCategory" >
< id column= "cid" property= "cid" jdbcType= "INTEGER" / >
< result column= "category_name" property= "categoryName" jdbcType= "VARCHAR" / >
< collection property= "categoryDetailList" ofType= "com.ynbw.goodsserver.entity.CategoryDetail" >
< result column= "detail_name" property= "detailName" jdbcType= "VARCHAR" / >
< result column= "detail_icno" property= "detailIcno" jdbcType= "VARCHAR" / >
< result column= "goods_id" property= "goodsId" jdbcType= "INTEGER" / >
< / collection>
< / resultMap>
< select id= "catLists" resultMap= "BaseResultMap3" >
select c. cid, c. category_name, d. category_name as detail_name, d. category_icno as detail_icno, d. goods_id
FROM goods_category c,
goods_category d
where c. cid = d. parent_id
< / select>
package com. ynbw. goodsserver. entity ;
import java. util. Date ;
import java. util. List ;
import java. util. Set ;
public class GoodsCategory {
private Integer cid;
private String categoryName;
private String categoryIcno;
private Integer parentId;
private String flbm;
private Integer goodsId;
private String bz;
private Boolean isDelete;
private Date addtime;
private String standby1;
private String standby2;
private String shr;
private Date shsj;
private String xgr;
private Date xgsj;
private List < CategoryDetail > categoryDetailList;
public List < CategoryDetail > getCategoryDetailList ( ) {
return categoryDetailList;
}
public void setCategoryDetailList ( List < CategoryDetail > categoryDetailList) {
this . categoryDetailList = categoryDetailList;
}
public Boolean getDelete ( ) {
return isDelete;
}
public void setDelete ( Boolean delete) {
isDelete = delete;
}
public Integer getCid ( ) {
return cid;
}
public void setCid ( Integer cid) {
this . cid = cid;
}
public String getCategoryName ( ) {
return categoryName;
}
public void setCategoryName ( String categoryName) {
this . categoryName = categoryName == null ? null : categoryName. trim ( ) ;
}
public String getCategoryIcno ( ) {
return categoryIcno;
}
public void setCategoryIcno ( String categoryIcno) {
this . categoryIcno = categoryIcno == null ? null : categoryIcno. trim ( ) ;
}
public Integer getParentId ( ) {
return parentId;
}
public void setParentId ( Integer parentId) {
this . parentId = parentId;
}
public String getFlbm ( ) {
return flbm;
}
public void setFlbm ( String flbm) {
this . flbm = flbm == null ? null : flbm. trim ( ) ;
}
public Integer getGoodsId ( ) {
return goodsId;
}
public void setGoodsId ( Integer goodsId) {
this . goodsId = goodsId;
}
public String getBz ( ) {
return bz;
}
public void setBz ( String bz) {
this . bz = bz == null ? null : bz. trim ( ) ;
}
public Boolean getIsDelete ( ) {
return isDelete;
}
public void setIsDelete ( Boolean isDelete) {
this . isDelete = isDelete;
}
public Date getAddtime ( ) {
return addtime;
}
public void setAddtime ( Date addtime) {
this . addtime = addtime;
}
public String getStandby1 ( ) {
return standby1;
}
public void setStandby1 ( String standby1) {
this . standby1 = standby1 == null ? null : standby1. trim ( ) ;
}
public String getStandby2 ( ) {
return standby2;
}
public void setStandby2 ( String standby2) {
this . standby2 = standby2 == null ? null : standby2. trim ( ) ;
}
public String getShr ( ) {
return shr;
}
public void setShr ( String shr) {
this . shr = shr == null ? null : shr. trim ( ) ;
}
public Date getShsj ( ) {
return shsj;
}
public void setShsj ( Date shsj) {
this . shsj = shsj;
}
public String getXgr ( ) {
return xgr;
}
public void setXgr ( String xgr) {
this . xgr = xgr == null ? null : xgr. trim ( ) ;
}
public Date getXgsj ( ) {
return xgsj;
}
public void setXgsj ( Date xgsj) {
this . xgsj = xgsj;
}
}
package com. ynbw. goodsserver. entity ;
import java. util. Date ;
public class CategoryDetail {
private Integer id;
private String detailName;
private String detailIcno;
private Integer parentId;
private Integer goodsId;
private String flbm;
private String bz;
private Boolean isDelete;
private Date addtime;
private String standby1;
private String standby2;
private String shry;
private Date shsj;
private String xgr;
private Date xgsj;
public Integer getId ( ) {
return id;
}
public void setId ( Integer id) {
this . id = id;
}
public String getDetailName ( ) {
return detailName;
}
public void setDetailName ( String detailName) {
this . detailName = detailName == null ? null : detailName. trim ( ) ;
}
public String getDetailIcno ( ) {
return detailIcno;
}
public void setDetailIcno ( String detailIcno) {
this . detailIcno = detailIcno == null ? null : detailIcno. trim ( ) ;
}
public Integer getParentId ( ) {
return parentId;
}
public void setParentId ( Integer parentId) {
this . parentId = parentId;
}
public Integer getGoodsId ( ) {
return goodsId;
}
public void setGoodsId ( Integer goodsId) {
this . goodsId = goodsId;
}
public String getFlbm ( ) {
return flbm;
}
public void setFlbm ( String flbm) {
this . flbm = flbm == null ? null : flbm. trim ( ) ;
}
public String getBz ( ) {
return bz;
}
public void setBz ( String bz) {
this . bz = bz == null ? null : bz. trim ( ) ;
}
public Boolean getIsDelete ( ) {
return isDelete;
}
public void setIsDelete ( Boolean isDelete) {
this . isDelete = isDelete;
}
public Date getAddtime ( ) {
return addtime;
}
public void setAddtime ( Date addtime) {
this . addtime = addtime;
}
public String getStandby1 ( ) {
return standby1;
}
public void setStandby1 ( String standby1) {
this . standby1 = standby1 == null ? null : standby1. trim ( ) ;
}
public String getStandby2 ( ) {
return standby2;
}
public void setStandby2 ( String standby2) {
this . standby2 = standby2 == null ? null : standby2. trim ( ) ;
}
public String getShry ( ) {
return shry;
}
public void setShry ( String shry) {
this . shry = shry == null ? null : shry. trim ( ) ;
}
public Date getShsj ( ) {
return shsj;
}
public void setShsj ( Date shsj) {
this . shsj = shsj;
}
public String getXgr ( ) {
return xgr;
}
public void setXgr ( String xgr) {
this . xgr = xgr == null ? null : xgr. trim ( ) ;
}
public Date getXgsj ( ) {
return xgsj;
}
public void setXgsj ( Date xgsj) {
this . xgsj = xgsj;
}
}