1.两表的关联关系为一对一
2.库存表Stock与商品信息表Product
3.库存表查询商品表里的商品名称,商品编号
库存表字段:
private String id;
private String stoSum;//库存量
private Integer stoSaleNum;//销售总数
private Long stoPrePrice;//上次进价
private Long stoCost;//成本
private Long stoSalePrice;//预售价格
private Long stoSumPrice;//库存总值
private String stoRemark;//备注
private Product product;
商品表字段:
private String id;
private String proNum;
private String proName;
private Double proPrice;
private String proUnit;
private String proColor;
private String proModel;
private Double proInPrice;
private Double proOutPrice;
private String proRemark;
private Tprosort tprosort;//关联表
4.HQL语句:
String query = "from Stock stock where 1=1"
if(!"".equals(proNum)&&proNum!=null){
query=query+" and stock.product.proNum=:proNum ";
}
if(!"".equals(proName)&&proName!=null){
query=query+" and stock.product.proName=:proName ";
}
Query q = session.createQuery(query);
if(!"".equals(proNum)&&proNum!=null){
q.setString("proNum", proNum);
}
if(!"".equals(proName)&&proName!=null){
q.setString("proName", proName);
}
List list = q.list();